Created
March 10, 2014 14:23
-
-
Save prabirshrestha/9465820 to your computer and use it in GitHub Desktop.
sample bus wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* usage: | |
* var Bus = require('../utils/bus'); | |
* var bus = new Bus({ url: 'amqp://guest:guest@localhost:5672' }); | |
* bus.connect(); // or bus.connectWithRetry(); | |
* | |
* bus.createQueueIfNotExists('queueName', function (err) { | |
* if (err) return console.log('error creating queue', err); | |
* console.log('queue created successfully'); | |
* }); | |
* | |
* bus.send('queueName', { data: 'something' }, function (err) { | |
* if (err) return console.log(err); | |
* console.log('message sent'); | |
* }); | |
* | |
* bus.createTopicIfNotExists('topicName', function (err) { | |
* if (err) return console.log('error creating topic', err); | |
* console.log('topic created successfully'); | |
* }); | |
* | |
* // topic must be created first before creating topic queue | |
* bus.createTopicQueueIfNotExists('topicName', 'queueName', 'routingKey', function (err) { | |
* if (err) return console.log('failed to create topic queue', err); | |
* console.log('topic queue created successfully'); | |
* }); | |
* | |
* bus.publish('topicName', 'routingKey', { data: 'something' }, function (err) { | |
* if (err) return console.log(err); | |
* console.log('message published'); | |
* }); | |
* | |
* // handles both queue and topic queues | |
* bus.on('queueName', function (msg, next) { | |
* console.log(msg); | |
* next(); // call next to ack or next(new Error()) to not ack | |
* }, function (err) { | |
* if (err) return console.log('failed to registered handler'); | |
* console.log('handler registered successfully'); | |
* }); | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment