Вопрос

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 ?

Это было полезно?

Решение 2

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

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top