-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.ts
More file actions
33 lines (28 loc) · 748 Bytes
/
server.ts
File metadata and controls
33 lines (28 loc) · 748 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
32
33
import amqp from "amqplib";
const queue = "product_inventory";
(async () => {
try {
const connection = await amqp.connect("amqp://localhost");
const channel = await connection.createChannel();
process.once("SIGINT", async () => {
await channel.close();
await connection.close();
});
await channel.assertQueue(queue, { durable: false });
await channel.consume(
queue,
(message) => {
if (message) {
console.log(
" [x] Received '%s'",
JSON.parse(message.content.toString())
);
}
},
{ noAck: true }
);
console.log(" [*] Waiting for messages. To exit press CTRL+C");
} catch (err) {
console.warn(err);
}
})();