cqrs

package module
v0.0.0-...-60d78a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

README

CQRS framework in go

Example test scenario

Documentation

Overview

Package cqrs provides a CQRS and Event Sourcing framework written in go influenced by the cqrs journey guide

Current version: experimental

For more in depth information on the CQRS journey visit the reference documentation at http://msdn.microsoft.com/en-us/library/jj554200.aspx

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventSourceBased

type EventSourceBased struct {
	// contains filtered or unexported fields
}

EventSourceBased provider a base class for aggregate times wishing to contain basis helper functionality for event sourcing

func NewEventSourceBased

func NewEventSourceBased(source interface{}) EventSourceBased

NewEventSourceBased constructor

func NewEventSourceBasedWithID

func NewEventSourceBasedWithID(source interface{}, id string) EventSourceBased

NewEventSourceBasedWithID constructor

func (*EventSourceBased) CallEventHandler

func (s *EventSourceBased) CallEventHandler(event interface{})

CallEventHandler routes an event to an aggregate's event handler

func (*EventSourceBased) Events

func (s *EventSourceBased) Events() []interface{}

Events returns a slice of newly created events since last deserialization

func (*EventSourceBased) ID

func (s *EventSourceBased) ID() string

ID provider the aggregate's ID

func (*EventSourceBased) SetID

func (s *EventSourceBased) SetID(id string)

SetID sets the aggregate's ID

func (*EventSourceBased) SetVersion

func (s *EventSourceBased) SetVersion(version int)

SetVersion sets the aggregate's Version

func (*EventSourceBased) Update

func (s *EventSourceBased) Update(versionedEvent interface{})

Update should be called to change the state of an aggregate type

func (*EventSourceBased) Version

func (s *EventSourceBased) Version() int

Version provider the aggregate's Version

type EventSourced

type EventSourced interface {
	ID() string
	SetID(string)
	Version() int
	SetVersion(int)
	Events() []interface{}
	CallEventHandler(event interface{})
}

EventSourced providers an interface for event sourced aggregate types

type EventSourcingRepository

type EventSourcingRepository interface {
	TypeRegistry
	Save(EventSourced) error
	Get(string, EventSourced) error
}

EventSourcingRepository is a repository for event source based aggregates

func NewRepository

func NewRepository(eventStreamRepository EventStreamRepository) EventSourcingRepository

NewRepository constructs an EventSourcingRepository

func NewRepositoryWithPublisher

func NewRepositoryWithPublisher(eventStreamRepository EventStreamRepository, publisher VersionedEventPublisher) EventSourcingRepository

NewRepositoryWithPublisher constructs an EventSourcingRepository with a VersionedEventPublisher to dispatch events once persisted to the EventStreamRepository

type EventStreamRepository

type EventStreamRepository interface {
	Save(string, []VersionedEvent) error
	Get(string, TypeRegistry) ([]VersionedEvent, error)
}

EventStreamRepository is a persistance layer for events associated with aggregates by ID

type EventTypeCache

type EventTypeCache map[string]reflect.Type

EventTypeCache is a map of strings to reflect.Type structures

type HandlersCache

type HandlersCache map[reflect.Type]func(source interface{}, event interface{})

HandlersCache is a map of types to functions that will be used to route event sourcing events

type MapBasedVersionedEventDispatcher

type MapBasedVersionedEventDispatcher struct {
	// contains filtered or unexported fields
}

MapBasedVersionedEventDispatcher is a simple implementation of the versioned event dispatcher. Using a map it registered event handlers to event types

func NewVersionedEventDispatcher

func NewVersionedEventDispatcher() *MapBasedVersionedEventDispatcher

NewVersionedEventDispatcher is a constructor for the MapBasedVersionedEventDispatcher

func (*MapBasedVersionedEventDispatcher) DispatchEvent

func (m *MapBasedVersionedEventDispatcher) DispatchEvent(event VersionedEvent) error

DispatchEvent executes all event handlers registered for the given event type

func (*MapBasedVersionedEventDispatcher) RegisterEventHandler

func (m *MapBasedVersionedEventDispatcher) RegisterEventHandler(event interface{}, handler VersionedEventHandler)

RegisterEventHandler allows a caller to register an event handler given an event of the specified type being received

type TypeRegistry

type TypeRegistry interface {
	GetHandlers(interface{}) HandlersCache
	GetEventType(string) (reflect.Type, bool)
	RegisterAggregate(aggregate interface{}, events ...interface{})
	RegisterEvents(events ...interface{})
	RegisterType(interface{})
}

TypeRegistry providers a helper registry for mapping event types and handlers after performance json serializaton

func NewTypeRegistry

func NewTypeRegistry() TypeRegistry

NewTypeRegistry constructs a new TypeRegistry

type VersionedEvent

type VersionedEvent struct {
	ID        string    `json:"id"`
	SourceID  string    `json:"sourceID"`
	Version   int       `json:"version"`
	EventType string    `json:"eventType"`
	Created   time.Time `json:"time"`
	Event     interface{}
}

VersionedEvent represents an event in the past for an aggregate

type VersionedEventDispatchManager

type VersionedEventDispatchManager struct {
	// contains filtered or unexported fields
}

VersionedEventDispatchManager is responsible for coordinating receiving messages from event receivers and dispatching them to the event dispatcher.

func NewVersionedEventDispatchManager

func NewVersionedEventDispatchManager(receiver VersionedEventReceiver) *VersionedEventDispatchManager

NewVersionedEventDispatchManager is a constructor for the VersionedEventDispatchManager

func (*VersionedEventDispatchManager) Listen

func (m *VersionedEventDispatchManager) Listen(stop <-chan bool) error

Listen starts a listen loop processing channels related to new incoming events, errors and stop listening requests

func (*VersionedEventDispatchManager) RegisterEventHandler

func (m *VersionedEventDispatchManager) RegisterEventHandler(event interface{}, handler VersionedEventHandler)

RegisterEventHandler allows a caller to register an event handler given an event of the specified type being received

type VersionedEventDispatcher

type VersionedEventDispatcher interface {
	DispatchEvent(VersionedEvent) error
	RegisterEventHandler(event interface{}, handler VersionedEventHandler)
}

VersionedEventDispatcher is responsible for routing events from the event manager to call handlers responsible for processing received events

type VersionedEventHandler

type VersionedEventHandler func(VersionedEvent) error

VersionedEventHandler is a function that takes a versioned event

type VersionedEventPublisher

type VersionedEventPublisher interface {
	PublishEvents([]VersionedEvent) error
}

VersionedEventPublisher is responsible for publishing events that have been saved to the event store\repository

type VersionedEventReceiver

type VersionedEventReceiver interface {
	ReceiveEvents(VersionedEventReceiverOptions) error
}

VersionedEventReceiver is responsible for receiving globally published events

type VersionedEventReceiverOptions

type VersionedEventReceiverOptions struct {
	TypeRegistry TypeRegistry
	Close        chan chan error
	Error        chan error
	ReceiveEvent chan VersionedEventTransactedAccept
}

VersionedEventReceiverOptions is an initalization structure to communicate to and from an event receiver go routine

type VersionedEventTransactedAccept

type VersionedEventTransactedAccept struct {
	Event                 VersionedEvent
	ProcessedSuccessfully chan bool
}

VersionedEventTransactedAccept is the message routed from an event receiver to the event manager. Sometimes event receivers designed with reliable delivery require acknowledgements after a message has been received. The success channel here allows for such acknowledgements

Directories

Path Synopsis
Package couchbase provides an event sourcing implementation in couchbase for the CQRS and Event Sourcing framework Current version: experimental
Package couchbase provides an event sourcing implementation in couchbase for the CQRS and Event Sourcing framework Current version: experimental
Package example provides an example scenario utilizing most of the aspects of the CQRS and Event Sourcing framework Current version: experimental
Package example provides an example scenario utilizing most of the aspects of the CQRS and Event Sourcing framework Current version: experimental
Package rabbit provides an event and command bus for the CQRS and Event Sourcing framework Current version: experimental
Package rabbit provides an event and command bus for the CQRS and Event Sourcing framework Current version: experimental
Package rethinkdb provides an event sourcing implementation in rethinkdb for the CQRS and Event Sourcing framework Current version: experimental
Package rethinkdb provides an event sourcing implementation in rethinkdb for the CQRS and Event Sourcing framework Current version: experimental

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL