-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathamqp_consumer.js
31 lines (27 loc) · 873 Bytes
/
amqp_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
const QUEUE = process.env.WSTOAMQQUEUE || "tasks";
export default async function amqp_consumer() {
try {
console.log("[*] Connecting");
let con = await require("amqplib").connect(
"amqp://tvobttnq:Ri6S8XroB9gRiIvSesqQMa2KcWI_IOkB@otter.rmq.cloudamqp.com/tvobttnq"
);
let ch = await con.createChannel();
let _ok = await ch.assertQueue(QUEUE, { durable: false });
console.log("[*] connected to amqp");
console.log("------------------------");
let amqpResponses = function(cllb) {
console.log("[*] wating for messages");
ch.consume(
QUEUE,
msg => {
console.log(`[*] Msg received: ${msg.content.toString()} \n\n`);
cllb(msg.content.toString());
},
{ noAck: true }
);
};
return { amqpResponses };
} catch (error) {
console.log("ERR:" + error);
}
}