1.1.0 • Published 2 years ago
@dangdoan/event-bus v1.1.0
event-bus
A simple event bus abstraction backed by RabbitMQ
import { initEventBus } from 'event-bus';
const eventBus = initEventBus(logger, connectionConfig, queueName);
const eventType = 'price_changed';
const event = {
type: eventType,
data: {
oldPrice: 5,
newPrice: 4,
},
};
await eventBus.publish(event);
await eventBus.subscribe(eventType, (data) => {
console.log(`Price changed from ${data.oldPrice} to ${data.newPrice}`);
});
Installation
This is a Node.js module. To install:
npm install event-bus
Features
- Publish event to event bus
- Subscribe to event bus to receive event
Tests
To run the test suite, run npm test