A simple distributed AMQP multi-channel event emitter.
rabbitmq-event simple and lightweight event emitter which supports multiple queues.
npm install rabbitmq-event
const RabbitmqEvent = require('rabbitmq-event');
var e = new RabbitmqEvent({
host: 'localhost',
connectionTimeout: 10000,
noDelay: true,
ssl: {
enabled : false
}
}, 'service.exchange', ['service', 'state']);
e.on('ready', function() {
e.on('service:test', function(data) {
console.log(data);
});
e.on('service:shutdown', function(data) {
e.quit();
});
e.pub('state:date', {
date: new Date()
}, true);
});
npm test
Initialise RabbitmqEvent module
connection
- connection settings objectexchangeName
- name of an exchangequeues
- array of AMQP queues
var connection = {
host: 'localhost',
connectionTimeout: 10000,
noDelay: true,
ssl: {
enabled : false
}
}
Publish event
eventName
- event name in following format -queue
:event
payload
- (optional) data will be delivered to subscribers
Subscribe a new event.
eventName
- event name in following format -queue
:event
payload
- (optional) incoming payload
Disconnect pub/sub sessions
Additional thanks to @egorfine, initially this module born from redis-emitter a while ago.
MIT