IronMQ empty message body from push queue when read from Node.JS / Express.JS

Problem

I'm playing with node + express + IronMQ and I'm encountering a little problem.

In my express.js POST callback I'm getting {} as request body but I'm sure that the message content is being pushed from my IronMQ message queue.

Any hint ?

Problem courtesy of: thomas.g

Solution

IronMQ have now updated their push queues to send custom headers. If you set the headers to 'Content-Type': 'application/json' in the list of subscribers when creating the queue, then the body gets parsed correctly. eg

# update groups queue
payload =
  subscribers: [
    {
      url: "#{process.env.ROOT_URL}/groups/update"
      headers:
        'Content-Type': 'application/json' # this fixes request parsing issue
    }
  ]
  push_type: 'multicast'
  retries: 3
  retries_delay: 10
  error_queue: 'groups_errors'

url = "https://mq-aws-us-east-1.iron.io/1/projects/#{process.env.IRON_MQ_PROJECT_ID}/queues/groups"

headers =
  'Authorization': "OAuth #{process.env.IRON_MQ_TOKEN}"
  'Content-Type': 'application/json'

result = HTTP.post url, {headers: headers, content: JSON.stringify(payload)}

Here's the relevant change on github

Solution courtesy of: ukoki

Discussion

Ok I've found both the reason of my problem and its solution. So to answer my own question:

Problem:


1) I'm receiving POST messages from an IronMQ push queue (http://dev.iron.io/mq/reference/push_queues/), their content type is text/plain.

2) I'm using connect.js middleware (express.connect) and it parses only application/json,application/x-www-form-urlencoded, and multipart/form-data. http://www.senchalabs.org/connect/bodyParser.html

So the body gets parsed and as its content type is not supported the result is {}

Solution:

In order to get the body of my text/plain request I had to parse it by myself as in https://stackoverflow.com/a/9920700

Discussion courtesy of: thomas.g

This recipe can be found in it's original form on Stack Over Flow.