Documentation
¶
Index ¶
- Constants
- Variables
- func ErrExecuteDidNotReturnAnEvent(commandType string) string
- func ImplementsITopic(topic ITopic) bool
- func IsBehaviorFound(behavior IBehavior) bool
- func NewDomainMsg[TID schema.IIdentity, TP schema.IPayload](aID TID, payload TP) *domainMsg[TID, TP]
- type ApplyEvt
- type BehaviorBuilder
- type BehaviorFtor
- type BehaviorPluginFtor
- type BehaviorType
- type Cmd
- type CommandType
- type Event
- func (e *Event) CreatedDate() time.Time
- func (e *Event) EventNumber() uint64
- func (e *Event) GetBehaviorID() (schema.IIdentity, error)
- func (e *Event) GetBehaviorId() string
- func (e *Event) GetBehaviorType() BehaviorType
- func (e *Event) GetData() []byte
- func (e *Event) GetEventId() string
- func (e *Event) GetEventType() EventType
- func (e *Event) GetEventTypeString() string
- func (e *Event) GetJsonMetadata(metaData interface{}) error
- func (e *Event) GetMetadata() []byte
- func (e *Event) GetPayload(data interface{}) error
- func (e *Event) GetStreamId() string
- func (e *Event) GetString() string
- func (e *Event) GetTimeStamp() time.Time
- func (e *Event) GetVersion() int64
- func (e *Event) SetBehaviorId(id string)
- func (e *Event) SetBehaviorType(aggregateType BehaviorType)
- func (e *Event) SetData(data []byte) *Event
- func (e *Event) SetMetadata(metaData interface{}) error
- func (e *Event) SetPayload(data interface{}) error
- func (e *Event) SetVersion(aggregateVersion int64)
- func (e *Event) String() string
- type EventType
- type Evt2CmdFunc
- type Evt2DocFtor
- type Evt2DocFunc
- type Evt2FactFunc
- type FApply
- type Fact2CmdFunc
- type GenBehaviorFtor
- type GenData2CmdFunc
- type GenEvt2FactFunc
- type GenReacter
- type Hope2CmdFunc
- type IApplyEvt
- type IBehavior
- type IBehaviorPlugin
- type ICmd
- type IEvt
- type IGenReacter
- type IGetBehavior
- type IGetBehaviorType
- type IGetCmdType
- type IGetEvtType
- type ILoadEvents
- type IModelStore
- type ISetBehavior
- type ISetBehaviorType
- type ISimpleBehavior
- type IStore
- type ITopic
- type ITryCmd
- type MediatorTopic
- type Position
- type RaiseEventsFunc
- type Reacter
- type Snapshot
- type StoreFtor
- type Topic
- type TryCmd
Constants ¶
const ( NoTopic = "No topic" InvalidEventVersion = "invalid event version" InvalidBehaviorID = "invalid behavior id" InvalidBehavior = "invalid behavior" InvalidBehaviorType = "invalid behavior type" InvalidCommandType = "invalid command type" InvalidEventType = "invalid event type" BehaviorNotFound = "behavior not found" AlreadyExists = "already exists" PayloadMustNotBeEmpty = "payload cmd_must not be empty" CommandCannotBeNil = "command cannot be nil" CommandMustHaveBehaviorID = "command cmd_must have behavior id" FailedToGetJsonData = "failed to get json data" CommandTypeMustNotBeEmpty = "command type cmd_must not be empty" EventHasNoBehaviorID = "event has no behavior id" NoApplierForEvent = "no F(apply) for event [%+v]" NoExecuterForCommand = "no F(try) for command [%+v]" HopeCannotBeNil = "Hope cannot be nil" ExecuteDidNotReturnAnEvent = "[%+v].execute did not return an event" TheBehaviorHasNoIDPleaseUseSetID = "the behavior has no Id, please use SetID()" BehaviorIDCannotBeNil = "behaviorID cannot be nil" )
const (
CannotBeNil = "behavior cannot be nil"
)
Variables ¶
var ( ErrCommandCannotBeNil = errors.New(CommandCannotBeNil) ErrPayloadMustNotBeEmpty = errors.New(PayloadMustNotBeEmpty) ErrCommandMustHaveBehaviorID = errors.New(CommandMustHaveBehaviorID) ErrFailedToGetJsonData = errors.New(FailedToGetJsonData) ErrCommandTypeMustNotBeEmpty = errors.New(CommandTypeMustNotBeEmpty) ErrAlreadyExists = errors.New(AlreadyExists) ErrBehaviorNotFound = errors.New(BehaviorNotFound) ErrInvalidEventType = errors.New(InvalidEventType) ErrInvalidCommandType = errors.New(InvalidCommandType) ErrInvalidBehavior = errors.New(InvalidBehavior) ErrInvalidBehaviorID = errors.New(InvalidBehaviorID) ErrInvalidEventVersion = errors.New(InvalidEventVersion) ErrEventHasNoBehaviorID = errors.New(EventHasNoBehaviorID) ErrInvalidBehaviorType = errors.New(InvalidBehaviorType) ErrHopeCannotBeNil = errors.New(HopeCannotBeNil) ErrNoTopic = errors.New(NoTopic) ErrTheBehaviorHasNoID = errors.New(TheBehaviorHasNoIDPleaseUseSetID) ErrBehaviorIDCannotBeNil = errors.New(BehaviorIDCannotBeNil) )
var (
ErrBehaviorCannotBeNil = fmt.Errorf(CannotBeNil)
)
Functions ¶
func ImplementsITopic ¶
func IsBehaviorFound ¶
IsBehaviorFound checks the version. If it is != 0, the behavior is found.
Types ¶
type ApplyEvt ¶
type ApplyEvt struct {
// contains filtered or unexported fields
}
func NewApplyEvt ¶
NewApplyEvt lets you create an Event Applier and requires that you pass an FApply function. your Event Applier is automatically injected into the Aggregate.
func (*ApplyEvt) GetAggregate ¶
func (*ApplyEvt) GetEventType ¶
func (*ApplyEvt) SetBehavior ¶
type BehaviorBuilder ¶
type BehaviorBuilder func() IBehavior
type BehaviorFtor ¶
type BehaviorFtor func() IBehavior
type BehaviorPluginFtor ¶
type BehaviorPluginFtor func() IBehaviorPlugin
type BehaviorType ¶
type BehaviorType string
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
func (*Cmd) GetBehaviorID ¶
func (*Cmd) GetCommandType ¶
func (c *Cmd) GetCommandType() CommandType
func (*Cmd) GetJsonPayload ¶
GetJsonPayload serializes the payload []byte and returns a reference to an IPayload struct.
func (*Cmd) GetPayload ¶
type CommandType ¶
type CommandType string
type Event ¶
type Event struct { EventId string EventType EventType Data []byte Timestamp time.Time AggregateType BehaviorType AggregateID string Version int64 Metadata []byte }
func (*Event) CreatedDate ¶
func (*Event) EventNumber ¶
func (*Event) GetBehaviorId ¶
GeTAID is the Id of the IBehavior that the Event belongs to
func (*Event) GetBehaviorType ¶
func (e *Event) GetBehaviorType() BehaviorType
GetAggregateType is the BehaviorType that the Event can be applied to.
func (*Event) GetEventId ¶
func (*Event) GetEventType ¶
func (*Event) GetEventTypeString ¶
GetEventType returns the EventType of the event.
func (*Event) GetJsonMetadata ¶
GetJsonMetadata unmarshal domain-specific metadata serialized as json for the Event.
func (*Event) GetMetadata ¶
GetMetadata is domain-specific metadata such as request Id, originating user etc.
func (*Event) GetPayload ¶
GetPayload json unmarshal data attached to the Event.
func (*Event) GetStreamId ¶
func (*Event) GetTimeStamp ¶
GetTimeStamp get timestamp of the Event.
func (*Event) GetVersion ¶
GetVersion is the version of the IBehavior after the Event has been applied.
func (*Event) SetBehaviorId ¶
func (*Event) SetBehaviorType ¶
func (e *Event) SetBehaviorType(aggregateType BehaviorType)
SetAggregateType set the BehaviorType that the Event can be applied to.
func (*Event) SetMetadata ¶
SetMetadata add domain-specific metadata serialized as json for the Event.
func (*Event) SetPayload ¶
SetPayload serialize to json and set data attached to the Event.
func (*Event) SetVersion ¶
SetVersion set the version of the IBehavior.
type Evt2CmdFunc ¶
type Evt2DocFtor ¶
type Evt2DocFtor[TEvt IEvt, TDoc schema.ISchema] func() Evt2DocFunc[TEvt, TDoc]
type Evt2DocFunc ¶
type Fact2CmdFunc ¶
type GenBehaviorFtor ¶
type GenData2CmdFunc ¶
type GenReacter ¶
type Hope2CmdFunc ¶
type IApplyEvt ¶
type IApplyEvt interface { IBehaviorPlugin IGetEvtType ApplyEvent(state schema.ISchema, evt IEvt) error }
IApplyEvt is an IBehaviorPlugin injector that allows us to inject Event Appliers into the Aggregate
type IBehavior ¶
type IBehavior interface { ISimpleBehavior Inject(agg IBehavior, actors ...BehaviorPluginFtor) IBehavior KnowsCmd(topic CommandType) bool KnowsEvt(topic EventType) bool }
IBehavior is the injector for Aggregates In an Event Sourced application, the Aggregate can be considered as the equivalent of the ActiveRecord in classic CrUD (Create, Upsert, Delete) applications. The Aggregate can be considered as the heart of an ES system, that unites State with Behavior. Its main responsibilities are:
- to build a (volatile) State from an ordered list of previously committed Events, that are sourced from the Event Stream that is identified by the Id.
- CanAcceptName Command requests and applying business logic that checks whether the Command (ICmd) is allowed to be executed or not, according to a number of Specifications, the Current State (see 1.) and the Command's FactPayload
- If Command execution is allowed, Raise a new Event and ApplyEvent it to itself, as to update the Current State to the New State.
Specifically for GO-SCREAM CMD Applications, given their modular nature, we rely on Aggregate Composition. Aggregate Composition is a technique that allows us to inject a series of BehaviorPluginFtor functors that create a feature's IApplyEvt and ITryCmd injectors, in order to compose an Aggregate that has all the capabilities required to process the Event Stream.
func NewBehavior ¶
func NewBehavior(behaviorType BehaviorType, state schema.IModel) IBehavior
NewBehavior initializes a new empty Aggregate
type IBehaviorPlugin ¶
type IBehaviorPlugin interface { ISetBehavior }
IBehaviorPlugin is an injector that allows us to inject ITryCmd and IApplyEvt injectors into the Aggregate in an elegant way.
type ICmd ¶
type ICmd interface { IGetCmdType GetBehaviorID() schema.IIdentity GetPayload() []byte // GetJsonPayload(pl schema.IPayload) error // SetJsonPayload(pl schema.IPayload) error }
ICmd is an injector that represents a behavior.Cmd
type IEvt ¶
type IEvt interface { IGetEvtType IGetBehaviorType ISetBehaviorType GetBehaviorID() (schema.IIdentity, error) GetStreamId() string EventNumber() uint64 CreatedDate() time.Time GetEventId() string GetTimeStamp() time.Time GetData() []byte SetData(data []byte) *Event GetPayload(data interface{}) error SetPayload(data interface{}) error GetEventTypeString() string GetBehaviorId() string GetVersion() int64 SetVersion(version int64) GetMetadata() []byte SetMetadata(metaData interface{}) error GetJsonMetadata(metaData interface{}) error GetString() string String() string SetBehaviorId(id string) }
type IGenReacter ¶
type IGenReacter[TEvt IEvt] interface { GenReacter[TEvt] }
type IGetBehavior ¶
type IGetBehavior interface {
GetBehavior() IBehavior
}
type IGetBehaviorType ¶
type IGetBehaviorType interface {
GetBehaviorType() BehaviorType
}
type IGetCmdType ¶
type IGetCmdType interface {
GetCommandType() CommandType
}
type IGetEvtType ¶
type IGetEvtType interface {
GetEventType() EventType
}
type ILoadEvents ¶
type IModelStore ¶
type IModelStore[T schema.ISchema] interface { IStore Exists(ctx context.Context, key string) (bool, error) Get(ctx context.Context, key string) (*T, error) Set(ctx context.Context, key string, data T) (string, error) Delete(ctx context.Context, key string) (*T, error) }
IModelStore is the Injector for a Store that is discriminated by the Read-Model Type Injector
type ISetBehavior ¶
type ISetBehavior interface {
SetBehavior(a IBehavior)
}
type ISetBehaviorType ¶
type ISetBehaviorType interface {
SetBehaviorType(behaviorType BehaviorType)
}
type ISimpleBehavior ¶
type ISimpleBehavior interface { IGetBehaviorType String() string TryCommand(ctx context.Context, command ICmd) (IEvt, contract.IFbk) ApplyEvent(event IEvt, isCommitted bool) error GetState() schema.IModel GetUncommittedEvents() []IEvt ClearUncommittedEvents() SetAppliedEvents(events []IEvt) GetAppliedEvents() []IEvt ToSnapshot() RaiseEvent(event IEvt) error GetVersion() int64 GetID() schema.IIdentity SetID(identity schema.IIdentity) IBehavior }
ISimpleBehavior is an injector that abstracts the implementation of a traditional monolithic Aggregate.
type ITryCmd ¶
type ITryCmd interface { IBehaviorPlugin IGetCmdType TryCommand(ctx context.Context, command ICmd) (IEvt, contract.IFbk) }
ITryCmd is an IBehaviorPlugin injector that allows us to inject Command Executors into the Aggregate
type MediatorTopic ¶
type MediatorTopic string
type Snapshot ¶
type Snapshot struct { Id string `json:"id"` Type BehaviorType `json:"type"` State []byte `json:"state"` Version uint64 `json:"version"` }
Snapshot Event Sourcing Snapshotting is an optimisation that reduces time spent on reading event from an event store.
func ToSnapshot ¶
ToSnapshot create new snapshot from the Aggregate state.
type StoreFtor ¶
type StoreFtor[T schema.ISchema] func() IModelStore[T]
StoreFtor of Type ISchema is a functor type for functions that return an IModelStore that returns a
type TryCmd ¶
type TryCmd struct {
// contains filtered or unexported fields
}
TryCmd is the -base receiver for executor extensions
func NewTryCmd ¶
func NewTryCmd(cmdType CommandType, raise RaiseEventsFunc) *TryCmd
NewTryCmd returns a new Command Executor for cndType and allows you to supply an executor function. It automatically registers the TryCmd into the Aggregate.
func (*TryCmd) GetBehavior ¶
GetBehavior returns the Aggregate tha this TryCmd is part of.
func (*TryCmd) GetCommandType ¶
func (e *TryCmd) GetCommandType() CommandType
func (*TryCmd) SetBehavior ¶
SetBehavior sets the behavior of this TryCmd