@theshelf/eventbroker
v0.0.3
Published
The event broker package provides a universal interaction layer with an actual event broker solution.
Keywords
Readme
Event Broker | The Shelf
The event broker package provides a universal interaction layer with an actual event broker solution.
This package is based on a publish / subscribe model.
Installation
npm install @theshelf/eventbrokerImplementations
Currently, there is only one implementation:
- Memory - non-persistent event broker based on the Node.js
EventEmitter.
We have plans to add a Kafka implementation later on.
Configuration
The used implementation needs to be configured in the .env file.
EVENT_BROKER_IMPLEMENTATION="memory"How to use
An instance of the configured event broker implementation can be imported for performing event operations.
import eventBroker from '@theshelf/eventbroker';
// Perform operations with the eventBroker instanceOperations
import eventBroker, { Publication, Subscription } from '@theshelf/eventbroker';
// Open connection
await eventBroker.connect();
// Close connection
await eventBroker.disconnect();
// Subscribe to an event
const subscription: Subscription = { channel: 'post', name: 'updated', handler: (postId: string) => { ... } };
await eventBroker.subscribe(subscription);
// Publish an event
const publication: Publication = { channel: 'post', name: 'updated', data: { postId: '123' } };
await eventBroker.publish(publication);
// Unsubscribe from an event
await eventBroker.unsubscribe(subscription);