Documentation ¶
Index ¶
- Variables
- func Subscribe[T Event](subscriber Subscriber, eventName EventName, handler TypedEventConsumer[T]) error
- type Callback
- type ErrUnhandledEvent
- type Event
- type EventBus
- type EventConsumer
- type EventEnvelope
- type EventName
- type LifeCycleListener
- type LifeCycleProvider
- type Option
- type Publisher
- type Subscriber
- type TypedEventConsumer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyEventName is returned when an empty event name is provided while subscribing. ErrEmptyEventName = errors.New("event name cannot be empty") // ErrBusNotRunning is returned when an operation is performed on a localBus that is not running. ErrBusNotRunning = errors.New("bus is not running") // ErrBusAlreadyRunning is returned when the localBus is already running. ErrBusAlreadyRunning = errors.New("bus is already running") )
Functions ¶
func Subscribe ¶ added in v0.5.1
func Subscribe[T Event](subscriber Subscriber, eventName EventName, handler TypedEventConsumer[T]) error
Subscribe subscribes to an event of a given type. It allows to use a typed handler.
Types ¶
type Callback ¶
Callback is a callback function that is called when an event is processed by the listener.
type ErrUnhandledEvent ¶ added in v0.5.4
func NewErrUnhandledEvent ¶ added in v0.5.4
func NewErrUnhandledEvent(eventName string, eventId uuid.UUID) *ErrUnhandledEvent
func (ErrUnhandledEvent) Error ¶ added in v0.5.4
func (e ErrUnhandledEvent) Error() string
type EventBus ¶
type EventBus interface { // Start starts the event bus to process events. Start() error // Stop stops the event bus. Stop() error Publisher Subscriber }
EventBus allows to publish and subscribe to events. It is a simple interface that allows to decouple the event publishing from the event handling. The handler can return an error, which will be returned by the Publish method. The publisher can publish as fire-and-forget, or wait for the handler to confirm the processing (replyHandler).
type EventConsumer ¶ added in v0.5.5
type EventEnvelope ¶
type EventEnvelope struct { Event Event Err error Ctx context.Context Callback Callback ShouldWait bool }
EventEnvelope is a wrapper around the event that is sent to the bus. It holds other information that is used by the bus to process the event.
func (*EventEnvelope) ProcessOptions ¶
func (e *EventEnvelope) ProcessOptions(options []Option)
ProcessOptions processes the options and sets the values on the envelope.
type LifeCycleListener ¶ added in v0.6.0
type LifeCycleProvider ¶ added in v0.6.0
type LifeCycleProvider interface { // AddLifecycleListener adds a listener that is called when the bus is started or stopped. AddLifecycleListener(listener LifeCycleListener) }
LifeCycleProvider is implemented by buses that allows to add a listener that is called when the bus is started or stopped.
type Option ¶
type Option func(*EventEnvelope)
func WithAckChan ¶ added in v0.5.5
func WithContext ¶ added in v0.5.1
type Subscriber ¶ added in v0.5.1
type Subscriber interface { // Subscribe subscribes to an event. // The consumer will be called when the event is published. // The consumer can return an error, which will be returned by the Publish method. Subscribe(eventName EventName, consumer EventConsumer) error }