Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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?

like image 296
Adam Matan Avatar asked Dec 10 '15 11:12

Adam Matan


People also ask

Can we send JSON in RabbitMQ?

In this example a message containing sample sales data in JSON is received through an HTTP endpoint. This message is then converted to a string using a transformer and then sent to RabbitMQ using the AMQP connector. Once this message reaches the queue, it can be viewed throught he RabbitMQ web console.

Which annotation will make the class to send and receive JSON?

Send JSON Data in POST Spring provides a straightforward way to send JSON data via POST requests. The built-in @RequestBody annotation can automatically deserialize the JSON data encapsulated in the request body into a particular model object.


1 Answers

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.

enter image description here

like image 91
Adam Matan Avatar answered Oct 19 '22 22:10

Adam Matan