-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrabbitMQ.js
31 lines (26 loc) · 806 Bytes
/
rabbitMQ.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//RabbitMQ
const amqp = require('amqplib/callback_api');
const rabbitUrl = 'amqp://localhost';
const sendRabbitMQ = function sendRabbitMQ(queueName, data) {
amqp.connect(rabbitUrl, function (error0, connection) {
if (error0) {
throw error0;
}
connection.createChannel(function (error1, channel) {
if (error1) {
throw error1;
}
var queue = queueName;
channel.assertQueue(queue, {
durable: false
});
channel.sendToQueue(queue, Buffer.from(data));
console.log(" [x] Sent %s", data);
});
setTimeout(function () {
connection.close();
//process.exit(0);
}, 500);
});
}
module.exports = sendRabbitMQ;