Skip to content

Instantly share code, notes, and snippets.

@alifrizkip
Last active April 11, 2018 07:10
Show Gist options
  • Save alifrizkip/91dfec0393fe2a88872c79cffb04710a to your computer and use it in GitHub Desktop.
Save alifrizkip/91dfec0393fe2a88872c79cffb04710a to your computer and use it in GitHub Desktop.
RabbitMQ consumer.js
const amqp = require('amqplib') // Import library amqp
amqp.connect('amqp://localhost')
.then(conn=> {
return conn.createChannel().then(ch => {
const ok = ch.assertQueue('hello', { durable: false }) // Deklarasi antrian
ok.then(() => {
/* Menangkap pesan yang dikirimkan oleh RabbitMQ */
return ch.consume('hello', msg => console.log('- Received', msg.content.toString()), { noAck: true })
})
.then(() => {
console.log('* Waiting for messages. Ctrl+C to exit')
})
})
}).catch(console.warn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment