Rabbitmq & JSON Messages

1,329 views
Skip to first unread message

Sally Fikry

unread,
Oct 26, 2016, 12:48:36 PM10/26/16
to rabbitmq-users
I built a java client to read from rabbitmq, then republish to an exchange.

This works very well with text messages, but when it comes to JSON messages, the behavior is inconsistent.
Sometimes the it is not properly displayed, sometimes has unreadable chars at the start and some other time works just fine.

I'm setting the content-type='application/
json' while publish the message.

The data is just received and sent as a byte [] with UTF-8 encoding.

Is there any special handling that should be done for JSON messages?

Michael Klishin

unread,
Oct 26, 2016, 12:52:04 PM10/26/16
to rabbitm...@googlegroups.com
RabbitMQ always receives and delivers immutable binary blobs. It's up to client
libraries how they encode, decode and otherwise treat message bodies.

Java and .NET clients simply pass the blogs down to consumers you register, that's it.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Sally Fikry

unread,
Oct 26, 2016, 1:01:16 PM10/26/16
to rabbitmq-users
My java client also read & publish the messages also as blobs with no message manipulation, but the display of JSON on the rabbitmq mngmt console is not consistent.
When I display the output to a file rather than the output queue, it is displayed correctly.

Michael Klishin

unread,
Oct 26, 2016, 1:03:11 PM10/26/16
to rabbitm...@googlegroups.com
RabbitMQ management UI doesn't pay attention to the content type either. I suspect that it is an escaping
issue of some kind in the UI code.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sally Fikry

unread,
Oct 26, 2016, 1:20:07 PM10/26/16
to rabbitmq-users
Would you elaborate more on this point? & how can I trace the cause on this problem?

My client doesn't have any UI, just java code.



On Wednesday, October 26, 2016 at 6:48:36 PM UTC+2, Sally Fikry wrote:

Michael Klishin

unread,
Oct 26, 2016, 2:06:31 PM10/26/16
to rabbitm...@googlegroups.com
I thought you were referring to the RabbitMQ management UI.

RabbitMQ does not care what payload encoding is used. Inspect your publishers and consumers. Capturing traffic with Wireshark can be quite useful as well. There is a guide on rabbitmq.com.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

V Z

unread,
Oct 28, 2016, 1:08:55 AM10/28/16
to rabbitmq-users
We send and receive json all the time with no issues. I would review what your app is doing first.

Sally Fikry

unread,
Nov 2, 2016, 4:23:00 AM11/2/16
to rabbitmq-users
After a lot of investigations, it seems like the output buffer is overridden, that's why we see misplaced output.
I need help to know if my code is thread safe or not,

Here's the scenario:
- I created a single queuing consumer (so single thread) that listens to a certain rabbitmq queue and waits for the next delivery inside a loop.
- each delivery triggers a construction of JSON message, converted to a new byte array then to be sent to a rabbitmq exchange using a routing key.

I'm using basicPublish method and it is said to be blocking calls and thread safe in the documentation.

What could go wrong with  this scenario to cause this behavior?

Arnaud Cogoluegnes

unread,
Nov 2, 2016, 12:05:57 PM11/2/16
to rabbitm...@googlegroups.com
Your scenario looks correct, but we'd need more information. The problem could be in the JSON document creation (not RabbitMQ-related, and JSON libs are usually thread-safe, but we never know) or also some bug in the frame creation in the Java client (unlikely, many people are doing what you do and don't complain).

Is this reproducible in a simple program or even better in a test?

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages