-
Notifications
You must be signed in to change notification settings - Fork 196
Event Bus
Giau Tran Minh edited this page Dec 12, 2018
·
2 revisions
The event bus will delegate published events to a handler. There is currently only a local event bus which can be imported as follows:
import (
...
eventbus "github.com/looplab/eventhorizon/eventbus/local"
)
func Setup() {
eventBus := eventbus.NewEventBus()
}
One must then add an event handler. An event handler can match all events or specific events. The events are then pass on to an implementation of EventHandler
There are various event handlers available already:
- github.com/looplab/eventhorizon/publisher/local
- github.com/looplab/eventhorizon/publisher/gpc
- github.com/looplab/eventhorizon/publisher/redis
- github.com/looplab/eventhorizon/eventhandler/cron
- github.com/looplab/eventhorizon/eventhandler/projector
- github.com/looplab/eventhorizon/eventhandler/saga
Add a handler to the event bus by specifying a Matcher
eventBus.AddHandler(eh.MatchAnyEventOf(
InviteCreatedEvent,
InviteAcceptedEvent,
InviteDeclinedEvent,
InviteConfirmedEvent,
InviteDeniedEvent,
), invitationProjector)
It is crucial to link an event bus to an event publisher so that events can be added to the aggregate store