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. Example usage of the AMQP version can be found in my rabbitmq-samples git repository under the "batch-amqp-itemreader-writer" module. Until Spring Batch 2.2.0 is released, you will need to clone and install to your local maven repository the master branch of Spring Batch, then remove the comment around the batch-amqp-itemreader-writer module in the rabbitmq-samples main POM and build the samples.

    Update: this sample is now deprecated as it has been merged into the Spring Batch samples project as of 2.2.0. See spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java for more details. Thanks to Wayne Lund for taking interest in the sample and merging it in!

    5 comments:

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

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

        Delete
    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:
      http://forum.springsource.org/showthread.php?133978-Batch-message-consuming-with-Spring-AMQP-amp-Spring-Mail

      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.)


      Regards.
      --Jason

      ReplyDelete
    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.

      ReplyDelete