How to send JSON payload to RabbitMQ using the web plugin?

I have a RabbitMQ 3.4.2 instance with a web management plugin installed.

When I push to the message {'operationId': 194} to the queue using Python's kombu queue package, the message is read on the other end as a dictionary.

However, when I send the message using the web console:

I get the following error on the receiving end:

operation_id = payload['operationId']
TypeError: string indices must be integers

I have tried adding a content-type header and property, with no success.

Since the reader code is the same, it means that the web sender does not mark the sent message as a JSON / dictionary payload, and therefore it is read as a string on the other end.

Any idea how to mark a message as a JSON message using the RabbitMQ web console?

Asked By: Adam Matan
||

Answer #1:

I had to use content_type instead of content-type (an underscore instead of a hyphen).

This is a pretty questionable design decision, because the standard everybody knows is content-type.

Answered By: Adam Matan

Answer #2:

You need to de-serialize the output.

import json
payload = json.loads(payload)
operation_id = payload['operationId']

In addition {'operationId': 194} is not valid JSON. Although it looks like you use double quotes in the screenshot, but make sure you replace the single quotes with double quotes.

Edit: So you are correct, kombu should handle this. Looking at the code it's likely that the header is case-sensitive. Change the properties header from Content-Type to content-type.

Answered By: eandersson
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .



# More Articles