Event Publishers and Subscribers
🚧
This page is under construction.
Event publishers
Whenever the EventStore appends events, the produced EventEnvelopes get published by the EventPublishers that are registered in the EventBus. A default EventPublisher takes care of publishing events internally, which allows us to create and register EventSubscribers that automatically listen for these events.
@EventSubscriber(AccountOpenedEvent)
export class AccountOpenedEventSubscriber implements IEventSubscriber {
handle(envelope: EventEnvelope<AccountOpenedEvent>) {
...
}
}
To register an additional EventPublisher to push your EventEnvelopes to Redis, SNS, Kafka, etc. simply create one and register it as a provider. This doesn't replace the default EventPublisher, but adds an additional one to the EventBus.
@EventPublisher()
export class CustomEventPublisher implements IEventPublisher {
async publish(envelope: EventEnvelope<IEvent>): Promise<void> {
...
}
}