Tuesday, June 14, 2011

How to receive what was sent by convertAndSend using JsonMessageConverter for Rabbit MQ?


Genereally this comes into the picture when we use JsonMessageConverter for sending and receiving message in RabbitMQ.
We generally get Message object (org.springframework.amqp.core.Message) in onMessage(Message message) of receiver which is of form JSON. To get the desired value from this JSON object use this code in listener  i.e. onMessage(Message message) of receiver

JsonMessageConverter jmc = new JsonMessageConverter();
                   TestUser u = (TestUser)jmc.fromMessage(message);
               System.out.println("received: " + u.getName());

No comments: