Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEngineRequired is returned when the eGo engine is not set ErrEngineRequired = errors.New("eGo engine is not defined") // ErrEngineNotStarted is returned when the eGo engine has not started ErrEngineNotStarted = errors.New("eGo engine has not started") // ErrUndefinedEntity is returned when sending a command to an undefined entity ErrUndefinedEntity = errors.New("eGo entity is not defined") )
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine represents the engine that empowers the various entities
func NewEngine ¶
func NewEngine(name string, eventsStore eventstore.EventsStore, opts ...Option) *Engine
NewEngine creates an instance of Engine
func (*Engine) AddProjection ¶
func (x *Engine) AddProjection(ctx context.Context, name string, handler projection.Handler, offsetStore offsetstore.OffsetStore, opts ...projection.Option) error
AddProjection add a projection to the running eGo engine and start it
func (*Engine) Subscribe ¶
func (x *Engine) Subscribe(ctx context.Context) (eventstream.Subscriber, error)
Subscribe creates an events subscriber
type Entity ¶
type Entity[T State] struct { // contains filtered or unexported fields }
Entity defines the event sourced persistent entity This handles commands in order
func NewEntity ¶
func NewEntity[T State](ctx context.Context, behavior EntityBehavior[T], engine *Engine) (*Entity[T], error)
NewEntity creates an instance of Entity
func (Entity[T]) SendCommand ¶
func (x Entity[T]) SendCommand(ctx context.Context, command Command) (resultingState T, revision uint64, err error)
SendCommand sends command to a given entity ref. This will return: 1. the resulting state after the command has been handled and the emitted event persisted 2. nil when there is no resulting state or no event persisted 3. an error in case of error
type EntityBehavior ¶
type EntityBehavior[T State] interface { // ID defines the id that will be used in the event journal. // This helps track the entity in the events store. ID() string // InitialState returns the event sourced actor initial state. // This is set as the initial state when there are no snapshots found the entity InitialState() T // HandleCommand helps handle commands received by the event sourced actor. The command handlers define how to handle each incoming command, // which validations must be applied, and finally, which events will be persisted if any. When there is no event to be persisted a nil can // be returned as a no-op. Command handlers are the meat of the event sourced actor. // They encode the business rules of your event sourced actor and act as a guardian of the event sourced actor consistency. // The command eventSourcedHandler must first validate that the incoming command can be applied to the current model state. // Any decision should be solely based on the data passed in the commands and the state of the Behavior. // In case of successful validation, one or more events expressing the mutations are persisted. // Once the events are persisted, they are applied to the state producing a new valid state. // Every event emitted are processed one after the other in the same order they were emitted to guarantee consistency. // It is at the discretion of the application developer to know in which order a given command should return the list of events // This is really powerful when a command needs to return two events. For instance, an OpenAccount command can result in two events: one is AccountOpened and the second is AccountCredited HandleCommand(ctx context.Context, command Command, priorState T) (events []Event, err error) // HandleEvent handle events emitted by the command handlers. The event handlers are used to mutate the state of the event sourced actor by applying the events to it. // Event handlers must be pure functions as they will be used when instantiating the event sourced actor and replaying the event journal. HandleEvent(ctx context.Context, event Event, priorState T) (state T, err error) }
EntityBehavior defines an event sourced behavior when modeling a CQRS EntityBehavior.
type Option ¶
type Option interface { // Apply sets the Option value of a config. Apply(e *Engine) }
Option is the interface that applies a configuration option.
func WithCluster ¶
func WithCluster(provider discovery.Provider, partitionCount uint64, minimumPeersQuorum uint16, host string, remotingPort, gossipPort, peersPort int) Option
WithCluster enables cluster mode
func WithTelemetry ¶
WithTelemetry sets the telemetry engine