-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsumer.js
51 lines (47 loc) · 1.06 KB
/
consumer.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var amqp = require("amqplib/callback_api");
amqp.connect("amqp://localhost", function (error0, connection) {
if (error0) {
throw error0;
}
connection.createChannel(function (error1, channel) {
if (error1) {
throw error1;
}
var exchange = "jobs";
channel.assertExchange(exchange, "x-delayed-message", {
autoDelete: false,
durable: true,
passive: true,
arguments: {
"x-delayed-type": "direct",
},
});
channel.assertQueue(
"",
{
exclusive: true,
},
function (error2, q) {
if (error2) {
throw error2;
}
console.log(
" [*] Waiting for messages in %s. To exit press CTRL+C",
q.queue
);
channel.bindQueue(q.queue, exchange, "");
channel.consume(
q.queue,
function (msg) {
if (msg.content) {
console.log(" [x] %s", msg.content.toString());
}
},
{
noAck: true,
}
);
}
);
});
});