Last active
May 19, 2023 05:01
-
-
Save 5minslearn/1c7a63cdfaef99accb503857d9afbcf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment