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!
This is great, Chris!!
ReplyDeleteReally great example of adding a new Reader/Writer. Would you mind if we add it into spring-batch-samples?
ReplyDeleteSure can -- let me know if you would prefer to do it or I can submit a pull request.
DeleteThanks for sharing, Chris.
ReplyDeleteI 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
Hi Jason,
ReplyDeletePer 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.