Skip to content
Giau Tran Minh edited this page Dec 12, 2018 · 2 revisions

Event Bus

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()
}

Event Handler

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

Clone this wiki locally