I have two separate Java apps which I need to send messages between via RabbitMQ using spring-rabbit. In the app which is the producer I am using JsonMessageConverter
as the message converter for my RabbitTemplate
to convert my Java objects to JSON messages before they get sent to the queue.
In the other app which is the consumer I want to convert the JSON messages back to Java objects. I have tried using SimpleMessageListenerContainer
with a custom MessageListener
and I can get the Message
s from the queue, but I don't know to convert them from JSON back to Java objects.
How do I use JsonMessageConverter
when consuming messages asynchronously from RabbitMQ?
I ended up using a MessageListenerAdapter
with a custom delegate object and JsonMessageConverter
as the MessageConverter
. Like so:
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.setMessageListener(new MessageListenerAdapter(new EventHandler(), new JsonMessageConverter()));
My EventHandler
class has a single method called handleMessage which gets the deserialized JSON object passed to it.