Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker interface {
Subscribe(ctx context.Context) (EventSource, error)
Unsubscribe(src EventSource) (hasMore bool, err error)
}
Broker provides a friendly interface to fan-out events to as many subscribers registered with it. Notice that an explicit unsubscription is necessary even with a context.Context being sent on the subscription call (to be improved).
type BrokerPool ¶
type BrokerPool interface {
Subscribe(ctx context.Context, id string, factoryArg interface{}) (EventSource, error)
}
BrokerPool manages a group of brokers which can be accessed and retrieved via an ID. It also simplifies the access to the brokers themselves, providing a single Subscribe function which automatically makes the unsubscription when the context is cancelled.
The EventSourceFactory passed as argument to the constructor should create a new EventSource channel, using the optional factoryArg that is passed on subscription.
In the simplest case, for example for messaging events between internal application components, there could be a single set of EventSources and the factory would grab them by their ID and return otherwise return an error for inexistent event source. In more complex scenarios, these event sources could be actual subscriptions to some remote messaging service for example Redis or RabbitMQ.
func NewPool ¶
func NewPool(factory EventSourceFactory) BrokerPool
type EventSource ¶
type EventSource <-chan Event
type EventSourceFactory ¶
type EventSourceFactory func(ctx context.Context, id string, arg interface{}) (EventSource, error)