Skip to content

Instantly share code, notes, and snippets.

@5minslearn
Last active May 19, 2023 04:58
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/f7f53295e107e50424a762739f3747d9 to your computer and use it in GitHub Desktop.
Save 5minslearn/f7f53295e107e50424a762739f3747d9 to your computer and use it in GitHub Desktop.
import amqp from "amqplib";
const queue = "product_inventory";
const text = {
item_id: "macbook",
text: "This is a sample message to send receiver to check the ordered Item Availablility",
};
(async () => {
let connection;
try {
connection = await amqp.connect("amqp://localhost");
const channel = await connection.createChannel();
await channel.assertQueue(queue, { durable: false });
channel.sendToQueue(queue, Buffer.from(JSON.stringify(text)));
console.log(" [x] Sent '%s'", text);
await channel.close();
} catch (err) {
console.warn(err);
} finally {
if (connection) await connection.close();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment