rabbitmq-pubsub
v0.6.0
Published
RabbitMQ Publisher Subscriber
Downloads
6
Maintainers
Readme
RabbitMQ Publisher Subscriber
A promise based API on top of ampqlib.
Install
$ npm install --save rabbitmq-pubsub
Usage
Publisher
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');
})
Subscriber
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)
Test
Make sure the rabbitmq server is running locally before running the test
$ npm test
License
MIT © Frederic Heem