Last active
September 10, 2021 15:43
-
-
Save nikostoulas/4251c0e8b21ecef2082415dd4de0db57 to your computer and use it in GitHub Desktop.
Calculator - Billing service RPC examples
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
// boilerplate to connect with RabbitMQ | |
const rabbit = require(‘./connect’); | |
rabbit.createQueue(‘add’, { durable: false }, (msg, ack) => { | |
const numbers = JSON.parse(msg.content.toString()); | |
ack(null, numbers[0] + numbers[1]); | |
}); |
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 rabbit = require(‘./connect’); | |
async function consume() { | |
const sum = await rabbit.getReply(‘add’, [1, 2]); | |
console.log(sum); | |
} | |
consume(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment