When we talk about RabbitMQ in Async Mode using spring and has the requirement where message is send by application working in different language, in that case it becomes mandatory for us use the default JsonMessageConverter provided by Spring for AMQP. This class helps us to marshal and demarshal the message before sending to the Exchange/Queue and receiving it to client.
Please find the below code TestSendAsycRMQ class send the message into the Exchange testAsyncExchange with routing key testAsyncRK, when the message enter the queue testAsyncQueue as per the configuration in rabbitConfiguration.xml it will invoke messageListener which is our receiver class rabbitMQ.TestReceiverAsycRMQ.
How the Spring flow work here:
We are providing SimpleMessageListenerContainer class with connectionFactory and queuename along with listener. connectionFactory helps SimpleMessageListenerContainer to get the connection. Further in our TestSendAsycRMQ we create the instance of RabbitTemplate which will refer to bean id=”rabbitTemplate” of rabbitConfiguration.xml by initializing it with default messageConverter as JsonMessageConverter.
Note: To work with JsonMessageConverter for AMQP we need to have jackson-mapper-asl-1.5.8.jar and jackson-core-asl-1.5.3.jar in your class path.