Hermes
Simplified abstraction interface to amqp.node
Publish & subscribe to RabbitMQ queues with simplified publish & subscribe interface
methods.
- Connects to RabbitMQ server, establishes a channel, asserts defined queues
- Queues will be created as
durabale
queues, not transient
. persistent
messages will be saved to disk and survivie broker restarts. Queue Durability
- Automatically buffers publish & subscribe calls until connection is established. (No need to wait for connection to be established before using
publish
or subscribe
methods from your application.) - Tracks references to subscribe callbacks and provides functionality to stop receiving jobs for one or all task queues. (Very similar to EventEmitter unsubscribe functionality)
- Automatically encodes objects/strings as buffers on publish and decodes to JS Object literals for subscribe callbacks
- Provides subscribe callback with simplified
done
method to send ack message to RabbitMQ and remove tasks from queue
USAGE
var hermes = require('runnable-hermes').hermesSingletonFactory({
name: 'service name',
hostname: 'localhost',
port: '5672',
username: 'guest',
password: 'guest',
heartbeat: 10,
persistent: true,
prefetch: 10
queues: [
'task-queue-1',
'task-queue-2'
],
publishedEvents: [
'task-queue-3',
'task-queue-4'
],
subscribedEvents: [
'task-queue-5',
'task-queue-6'
]
}).connect();
var jobCallback = function (data, done) {
done();
};
hermes.subscribe('valid-queue-name', jobCallback);
hermes.publish('valid-queue-name', {foo: 'bar'});
hermes.unsubscribe('valid-queue-name', jobCallback, function (err) {
});
hermes.unsubscribe('valid-queue-name', null, function (err) {});
hermes.close(cb);
hermes.connect(cb);
var queues = hermes.getQueues();
hermes
.connect()
.on('ready', function () {
console.log('hermes connected to RabbitMQ & queues asserted');
});
hermes.on('publish', function (queueName, data) {
console.log('hermes publish action', queueName, data);
});
hermes.publish('valid-queue-name', {foo: 'bar'});
hermes.on('subscribe', function (queueName, handlerFn) {
console.log('hermes subscribe action', queueName, handlerFn);
});
hermes.subscribe('valid-queue-name', subscribeCallback);
hermes.unsubscribe('valid-queue-name', null, unsubscribeAllCallback);
hermes.on('unsubscribe', function (queueName, handlerFn) {
console.log('hermes unsubscribe action', queueName, handlerFn);
});
TESTS
- Tests & coverage are run using Lab
$ npm test
$ npm run test-cov # will auto open Google Chrome
LICENSE
MIT