Last active
April 11, 2018 07:10
-
-
Save alifrizkip/91dfec0393fe2a88872c79cffb04710a to your computer and use it in GitHub Desktop.
RabbitMQ consumer.js
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 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