-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublisher.js
39 lines (32 loc) · 900 Bytes
/
publisher.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
var _ = require("lodash");
const q = "tasks";
async function amqp() {
try {
console.log("[*] Connecting");
let con = await require("amqplib").connect(
"amqp://tvobttnq:[email protected]/tvobttnq"
);
let ch = await con.createChannel();
let _ok = await ch.assertQueue(q, { durable: false });
console.log(`[*] sending Hello message`);
ch.sendToQueue(q, Buffer.from("Hello!"));
_.range(10).forEach(m => {
console.log(`[*] sending message ${m} from loop`);
ch.sendToQueue(q, Buffer.from("[*] message n: " + m));
});
console.log("[*] messages were sended");
return con;
//con.close();
} catch (error) {
console.log("ERR:" + error);
}
}
/* (async function() {
await amqp();
})(); */
amqp().then(con => {
setTimeout(function() {
con.close();
process.exit(0);
}, 500);
});