How to send JSON payload to RabbitMQ using web plugin?

I have an instance of RabbitMQ 3.4.2 with the web management plugin installed.

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

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

enter image description here

I get the following error on the receiving side:

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

I tried to add a title and a content-type property, without any success.

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

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

+7
json python queue rabbitmq
source share
2 answers

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

This is a rather dubious design decision, because the standard that everyone knows is content-type .

enter image description here

+13
source share

You need to de-serialize the output.

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

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

Edit: So, you're right, the combo should handle this. If you look at the code, the header is likely to be case sensitive. Change the property title from Content-Type to Content-Type .

+1
source share

All Articles