Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrModelNotSet is when a model factory is not set on the EventHandler. ErrModelNotSet = errors.New("model not set") // ErrModelRemoved is when a model has been removed. ErrModelRemoved = errors.New("model removed") // Returned if the model has not incremented its version as predicted. ErrIncorrectProjectedEntityVersion = errors.New("incorrect projected entity version") )
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { // Err is the error that happened when projecting the event. Err error // Projector is the projector where the error happened. Projector string // Event is the event being projected. Event eh.Event // EntityID of related operation. EntityID uuid.UUID // EntityVersion is the version of the entity. EntityVersion int }
Error is an error in the projector.
type EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
EventHandler is a CQRS projection handler to run a Projector implementation.
func NewEventHandler ¶
func NewEventHandler(projector Projector, repo eh.ReadWriteRepo, options ...Option) *EventHandler
NewEventHandler creates a new EventHandler.
func (*EventHandler) HandleEvent ¶
HandleEvent implements the HandleEvent method of the eventhorizon.EventHandler interface. It will try to find the correct version of the model, waiting for it the projector has the WithWait option set.
func (*EventHandler) HandlerType ¶ added in v0.4.0
func (h *EventHandler) HandlerType() eh.EventHandlerType
HandlerType implements the HandlerType method of the eventhorizon.EventHandler interface.
func (*EventHandler) SetEntityFactory ¶
func (h *EventHandler) SetEntityFactory(f func() eh.Entity)
SetEntityFactory sets a factory function that creates concrete entity types.
type Option ¶ added in v0.8.0
type Option func(*EventHandler)
Option is an option setter used to configure creation.
func WithEntityLookup ¶ added in v0.14.3
WithEntityLookup can be used to provide an alternative ID (from the aggregate ID) for fetching the projected entity. The lookup func can for example extract another field from the event or use a static ID for some singleton-like projections.
func WithIrregularVersioning ¶ added in v0.14.2
func WithIrregularVersioning() Option
WithIrregularVersioning sets the option to allow gaps in the version numbers. This can be useful for projectors that project only some events of a larger aggregate, which will lead to gaps in the versions.
func WithRetryOnce ¶ added in v0.14.10
func WithRetryOnce() Option
WithRetryOnce adds a single retry in case of version mismatch. Useful to let racy projections finish witout an error.
type Projector ¶
type Projector interface { // ProjectorType returns the type of the projector. ProjectorType() Type // Project projects an event onto a model and returns the updated model or // an error. Project(context.Context, eh.Event, eh.Entity) (eh.Entity, error) }
Projector is a projector of events onto models.