RabbitMQ Publisher Subscriber
A promise based API on top of ampqlib.
$ npm install --save rabbitmq-pubsub
var Publisher = require('rabbitmq-pubsub').Publisher;
var publisherOptions = {
exchange: 'user',
type: 'topic',
url: 'amqp://localhost'
};
var publisher = new Publisher(publisherOptions);
publisher.start()
.then(function() {
publisher.publish('myRoutingKey', 'Ciao');
})
var Subscriber = require('rabbitmq-pubsub').Subscriber;
var subscriberOptions = {
exchange: 'user',
queueName: 'user',
routingKeys:['user.regiser', 'user.resetpassword']
};
var subscriber = new Subscriber(subscriberOptions);
function onIncomingMessage(message) {
debug('onIncomingMessage ', message.fields);
assert(message);
assert(message.content);
assert(message.content.length > 0);
subscriber.ack(message);
//subscriber.nack(message);
};
subscriber.start(onIncomingMessage)
Make sure the rabbitmq server is running locally before running the test
$ npm test
MIT © Frederic Heem