Store/Serialize List as Message Spring AMQP

By : aces.
Source: Stackoverflow.com
Question!

I am new to Spring AMQP which uses RabbitMQ. I understand that this question addresses a broader issue. I want to store a list of objects into message which can be sent to consumers. Can anyone provide an easy solution to this problem?

I know Serialization can be a solution, but that will be an overkill for the simple application that I am using. The messages would be asynchronous in nature. Is there any other approach?

By : aces.


Answers

AMQP only supports one type of message - binary (bytes) - and this means you must serialize your object.

You do get to choose the type of serialization, though - for example JSON, XML or Java serialization.



You can use a MessageConverter, see the Spring RabbitMQ documentation: http://static.springsource.org/spring-amqp/docs/1.1.x/reference/htmlsingle/#d4e293

There is a JsonMessageConverter which is probably what you are looking for.

I recommend not to use standard Java serialization and the SimpleMessageConverter, because then your implementation will be bound to Java and that would defeat the whole idea of AMQPs protocol concept.

From the documentation:

With AMQP being a wire-level protocol, it would be unfortunate to lose
much of that advantage with such restrictions.

Here is a code example taken from the documentation:

By : lanoxx


This video can help you solving your question :)
By: admin