Last active
September 1, 2019 23:54
-
-
Save RafaelGSS/5ed685908096377609f6f377b077ad0c to your computer and use it in GitHub Desktop.
Communication between microservices - RabbitMQ - CW Pattern - consumer
This file contains hidden or 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') | |
async function createConnection (uri = 'guest:guest@localhost:5672') { | |
const connection = await amqp.connect('amqp://' + uri) | |
return connection | |
} | |
createConnection() | |
.then(conn => conn.createChannel()) | |
.then(ch => { | |
console.log('Channel created!') | |
const queue = 'messages' | |
ch.assertQueue(queue) | |
ch.consume(queue, function (msg) { | |
if (msg !== null) { | |
console.log('%s Received: %s', new Date(), msg.content.toString()) | |
ch.ack(msg) | |
} | |
}) | |
}); | |
// Consumer channel without prefetch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment