I was successfully consumed the message from rabbitmq, I can see the message if I add console.log(msg), but the problem is I can't get the msg outside the channel.consume
I tried to assign it to variable but it's still didn't work
const connection = await amqp.connect("amqp://localhost")
const channel = await connection.createChannel()
const queue = 'data-portal-response'
var messageString;
channel.consume(queue, msg => {
console.log('Checking message...');
if (msg !== null) {
messageString = msg.content.toString();
console.log('Acknowledging message..');
channel.ack(msg);
console.log('Acknowledged.');
return messageString;
} else {
console.log('No messages to consume.');
return null;
}
});
console.log(messageString);
I'm expecting the code to print messageString outside the consume part console.log(messageString);