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?
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
.
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
.