Last active
April 11, 2018 07:04
-
-
Save alifrizkip/5d3ce9f5a1b0f37ce62ab52509f1bc82 to your computer and use it in GitHub Desktop.
producer.js RabbitMQ
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
const amqp = require('amqplib') // Import library amqp | |
amqp.connect('amqp://localhost') | |
.then(conn => { | |
return conn.createChannel().then(ch => { | |
const q = 'hello' // Nama antrian adalah 'hello' | |
const msg = 'Hello world!' // Isi pesan yang dikirim ke RabbitMQ | |
const ok = ch.assertQueue(q, { durable: false }) // Membuat antrian 'hello' | |
return ok.then(() => { | |
ch.sendToQueue(q, Buffer.from(msg)) // Mengirim pesan ke RabbitMQ | |
console.log('- Sent', msg) | |
return ch.close() | |
}) | |
}).finally(() => conn.close()) | |
}).catch(console.warn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment