I want to pass JSON object to the RabbitMQ queue.
In the below code, I am using obj.toJSONString().getBytes() for converting Json object in to string, Is it possible to pass JSON object in the queue instead passing as string.
JSONObject obj = new JSONObject();
obj.put("Transaction","Test value");
channel.basicPublish("", queueName, null, obj.toJSONString().getBytes());
System.out.println(" [x] Sent '" + obj.toJSONString() + "'");
We can only send the data as bytes to a rabbitmq queue. So we have to convert the json object into string. In your code snippet, you have done by using the code - obj.toJSONString().getBytes(). This is the correct approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With