Skip to content

Instantly share code, notes, and snippets.

@alifrizkip
Last active April 11, 2018 07:04
Show Gist options
  • Save alifrizkip/5d3ce9f5a1b0f37ce62ab52509f1bc82 to your computer and use it in GitHub Desktop.
Save alifrizkip/5d3ce9f5a1b0f37ce62ab52509f1bc82 to your computer and use it in GitHub Desktop.
producer.js RabbitMQ
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