Kelly Kelly - 22 days ago 4x
Node.js Question

RabbitMQ and Node.js converting message buffer to JSON

I have a node.js app that connects to RabbitMQ to receive messages. When the messages come in and I output them to the console I get:
{ data: <Buffer 62 6c 61 68>, contentType: undefined }

How do I get a proper JSON or string out of this? Here is my example:

var amqp = require('amqp');

var connection = amqp.createConnection({ host: 'localhost' });

process.on('uncaughtException', function(err) {

connection.on('ready', function () {
// Use the default 'amq.topic' exchange
connection.queue('my-queue', function(q){

q.subscribe(function (message) {

The messages are being sent using the RabbitMQ management console (for testing purposes currently). In this example I sent a simple message with the topic of "test" and the body "blah".

I'm new to Node.js but I have tried to do


and I get nothing. Not even an error message. (not sure how to catch the issue)


When I do this I get [object Object] which doesn't help


Also does nothing and I get no error message. I assuming it's failing but why I don't get an exception is unknown to me.


The answer was right in front of me. Leaving this up in case someone else has the same issue, but the solution was:


I was getting the object and trying to convert it all and not the data property.