Skip to content

Instantly share code, notes, and snippets.

@nikostoulas
Last active September 10, 2021 15:43
Show Gist options
  • Save nikostoulas/4251c0e8b21ecef2082415dd4de0db57 to your computer and use it in GitHub Desktop.
Save nikostoulas/4251c0e8b21ecef2082415dd4de0db57 to your computer and use it in GitHub Desktop.
Calculator - Billing service RPC examples
// 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]);
});
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