I'm writing a simple server app using nodejs and i want to use rabbitmq as a message broker with other services. My problem is that i don't understand how can i reuse the channel object created asynchronously inside other files?
RabbitMQ has the following samle:
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'hello';
var msg = 'Hello World!';
ch.assertQueue(q, {durable: false});
ch.sendToQueue(q, new Buffer(msg));
console.log(" [x] Sent %s", msg);
});
setTimeout(function() { conn.close(); process.exit(0) }, 500);
});
I want to achieve something like that:
var channel = require('channelcreation');
// some express.js router logic
router.get('path', function(req, res) {
. . .
channel.send(...);
. . .
})