Documentation ¶
Index ¶
- Variables
- type EventBus
- func (b *EventBus) AddGlobalHandler(handler eventhorizon.EventHandler)
- func (b *EventBus) AddHandler(handler eventhorizon.EventHandler, event eventhorizon.Event)
- func (b *EventBus) AddLocalHandler(handler eventhorizon.EventHandler)
- func (b *EventBus) Close()
- func (b *EventBus) PublishEvent(event eventhorizon.Event)
- func (b *EventBus) RegisterEventType(event eventhorizon.Event, factory func() eventhorizon.Event) error
Constants ¶
This section is empty.
Variables ¶
var ErrCouldNotMarshalEvent = errors.New("could not marshal event")
ErrCouldNotMarshalEvent is when an event could not be marshaled into BSON.
var ErrCouldNotUnmarshalEvent = errors.New("could not unmarshal event")
ErrCouldNotUnmarshalEvent is when an event could not be unmarshaled into a concrete type.
var ErrEventNotRegistered = errors.New("event not registered")
ErrEventNotRegistered is when an event is not registered.
Functions ¶
This section is empty.
Types ¶
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus is an event bus that notifies registered EventHandlers of published events.
func NewEventBus ¶
NewEventBus creates a EventBus for remote events.
func NewEventBusWithPool ¶
NewEventBusWithPool creates a EventBus for remote events.
func (*EventBus) AddGlobalHandler ¶
func (b *EventBus) AddGlobalHandler(handler eventhorizon.EventHandler)
AddGlobalHandler adds a handler for global (remote) events.
func (*EventBus) AddHandler ¶
func (b *EventBus) AddHandler(handler eventhorizon.EventHandler, event eventhorizon.Event)
AddHandler adds a handler for a specific local event.
func (*EventBus) AddLocalHandler ¶
func (b *EventBus) AddLocalHandler(handler eventhorizon.EventHandler)
AddLocalHandler adds a handler for local events.
func (*EventBus) Close ¶
func (b *EventBus) Close()
Close exits the recive goroutine by unsubscribing to all channels.
func (*EventBus) PublishEvent ¶
func (b *EventBus) PublishEvent(event eventhorizon.Event)
PublishEvent publishes an event to all handlers capable of handling it.
func (*EventBus) RegisterEventType ¶
func (b *EventBus) RegisterEventType(event eventhorizon.Event, factory func() eventhorizon.Event) error
RegisterEventType registers an event factory for a event type. The factory is used to create concrete event types when receiving from subscriptions.
An example would be:
eventStore.RegisterEventType(&MyEvent{}, func() Event { return &MyEvent{} })