Skip to content

Instantly share code, notes, and snippets.

@mrsid96
Created July 7, 2020 18:42
Show Gist options
  • Save mrsid96/a7c1f28f80fa5cbede86b493229c6cb2 to your computer and use it in GitHub Desktop.
Save mrsid96/a7c1f28f80fa5cbede86b493229c6cb2 to your computer and use it in GitHub Desktop.
let workOnChannel = async (channel) => {
// ...
//Consumer listening to the queue, which was ealier created and bind with exchange
let { consumerTag } = await channel.consume(queue, function (msg) {
if (msg.content) {
let dataReceive = JSON.parse(msg.content.toString());
console.log(`[✓] Incomming message ${JSON.stringify(dataReceive)}`);
}
}, {
noAck: true
});
//Publisher pushing messages to the 'exchange' which was earlier defined
//Dummy data block
let data = {
message: "This is a sample message",
action: "nothing"
}
channel.publish(exchange, '', Buffer.from(JSON.stringify(data)));
// channel.sendToQueue(sessionId, Buffer.from(JSON.stringify(data)));
console.log(`[!] Data Pushed to ${exchange}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment