Created
June 21, 2019 06:48
-
-
Save pujianto/66ec5289d28e8307c164d7b8f0a079fc to your computer and use it in GitHub Desktop.
amqplib send multiple queues to RabbitMQ
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
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