Last active
May 19, 2023 04:58
-
-
Save 5minslearn/f7f53295e107e50424a762739f3747d9 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"; | |
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