Skip to content

Instantly share code, notes, and snippets.

@pujianto
Created June 21, 2019 06:48
Show Gist options
  • Save pujianto/66ec5289d28e8307c164d7b8f0a079fc to your computer and use it in GitHub Desktop.
Save pujianto/66ec5289d28e8307c164d7b8f0a079fc to your computer and use it in GitHub Desktop.
amqplib send multiple queues to RabbitMQ
const amqp = require('amqplib');
const connect = amqp.connect('amqp://localhost');
let queue1 = 'queue1', queue2 = 'queue2';
connect.then( conn => {
return conn.createChannel();
})
.then(ch => {
return Promise.all([ch.assertQueue(queue1), ch.assertQueue(queue2)]).then((ok1,ok2) => {
return Promise.resolve(ch);
});
})
.then(ch => {
var bufferMessage1 = Buffer.from('Message for queue1', 'utf8');
var bufferMessage2 = Buffer.from('Message for queue2', 'utf8');
ch.sendToQueue(queue1, bufferMessage1);
ch.sendToQueue(queue2, bufferMessage2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment