Building an event subscriber

Now that we can publish events on a RabbitMQ broker using the EventEmitter, we also need a possibility to listen to these events. This will be the purpose of the EventListener, which we will build in this section.

Like before, let's start by defining the interface that all event listeners (the AMQP event listener being one of them) should fulfil. For this, create the listener.go file in the todo.com/myevents/lib/msgqueue package:

package msgqueue 
 
type EventListener interface { 
  Listen(eventNames ...string) (<-chan Event, <-chan error, error) 
} 

This interface looks quite different than the event emitter's interface. This is because each call to the event emitter's Emit() method simply publishes one message immediately. ...

Get Cloud Native programming with Golang now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.