-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsumer.js
More file actions
31 lines (25 loc) · 860 Bytes
/
Copy pathconsumer.js
File metadata and controls
31 lines (25 loc) · 860 Bytes
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 amqp = require('amqplib');
async function connect() {
try {
const connection = await amqp.connect("amqp://localhost:5672");
const channel = await connection.createChannel();
const result = await channel.assertQueue("jobs");
channel.consume("jobs", message => {
const input = JSON.parse(message.content.toString());
console.log(`Job received successfully! ${input.number}`);
if(input.number == 3) {
channel.ack(message);
}
});
console.log("Waiting for messages in jobs queue...");
// Close the connection after 500ms
setTimeout(() => {
connection.close();
process.exit(0);
}, 500);
} catch (err) {
console.error(err);
process.exit(1);
}
}
connect();