networking sites

Thursday, August 30, 2012

Spring Batch AMQP ItemReader / ItemWriter

Spring Batch is my favorite Spring project and I noticed there was no AMQP ItemReader or ItemWriter implementation. As I am becoming more and more interested in RabbitMQ I put together an AMQP ItemReader / ItemWriter and made a pull request which was accepted and merged into the master branch (currently 2.2.0-BUILD-SNAPSHOT). At this time 2.2.0 is not released so if you would like to use the functionality wait until 2.2.0 is released or clone the master repository of Spring Batch located at:

  • Spring Batch Git

  • If you are interested in the change itself, it can be found in this commit. The reader and writer usage is fairly straight forward and similar to the JMS JmsItemReader and JmsItemWriter implementations.

    Update: 2.2.0 has been released and a sample can be found in the Spring Batch samples module. See:


    for more details. Thanks to Wayne Lund for taking interest in the sample and merging it in!


    1. Really great example of adding a new Reader/Writer. Would you mind if we add it into spring-batch-samples?

      1. Sure can -- let me know if you would prefer to do it or I can submit a pull request.

    2. Thanks for sharing, Chris.

      I cloned Spring Batch 2.2.0-BUILD-SNAPSHOT and run the Test Case that you wirting, look like AmqpItemWriter was not invoked and no message publish to MQ...

      I am a newbie to Spring Batch, perhaps i need read more docs about Spring Batch.

      But i am familiar with Spring AMQP, below link is why i begin study Spring Batch recently:

      About Batch message consuming with Spring AMQP, do you have any suggestions? Looking forward to your reply.

      (My english is not very good, apologize for that.)


    3. Hi Jason,

      Per the javadoc in AMQPJobFunctionalTests you first need to run AmqpMessageProducer which will populate the AMQP queue with messages.

      Then you run the test case (AMQPJobFunctionalTests) which will read messages from one queue and write to another. This demonstrates consuming (the reader) messages from the queue and producing (the writer) messages to another queue.

      Hopefully this helps, if not feel free to send me an email (chris @ dtzq . com) and ill help you out.

    4. Thanks. Can we use Request/Reply using AmqpItemWriter ?

    5. AmqpItemReader is used to read messages from AMQP, AmqpItemWriter is used to write messages. Looks like Gary has answered your question on SO.