-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducer.js
35 lines (32 loc) · 827 Bytes
/
producer.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
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";
var msg = process.argv.slice(2).join(" ") || "Hello World!";
let delay = 40000;
channel.assertExchange(exchange, "x-delayed-message", {
autoDelete: false,
durable: true,
passive: true,
arguments: {
"x-delayed-type": "direct",
},
});
channel.publish(exchange, "", Buffer.from(`msg delay: ${delay}`), {
headers: {
"x-delay": delay,
},
});
console.log(" [x] Sent %s", msg);
});
setTimeout(function () {
connection.close();
process.exit(0);
}, 500);
});