Skip to content

Instantly share code, notes, and snippets.

@5minslearn
Last active May 19, 2023 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5minslearn/1c7a63cdfaef99accb503857d9afbcf4 to your computer and use it in GitHub Desktop.
Save 5minslearn/1c7a63cdfaef99accb503857d9afbcf4 to your computer and use it in GitHub Desktop.
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