This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

There are two ways to do this - one is to define your own RepeatOperations, which is a bit complicated and messy. The better way in my opinion is to use AOP. Create a pointcut that includes the methods you want to retry. Then, create an instance of the class:

Comment

BatchMessageListenerContainer is definitely work in progress - hence it is in the integration test module, not the main release - but I certainly appreciate your interest.

The integration tests exercise the scenario you are interested in (I assume) where the retry forces a rollback and the message is re-presented by the middleware. The most relevant test is in ExternalRetryInBatchTests. But that doesn't use the BatchMessageListenerContainer - it just shows where the retry needs to be applied.

What you need is a stateful retry policy and a retry template wrapping your message processing. You could do that with the ItemReaderRetryPolicy and your own container (as in the integration test), or you could write your own stateful retry policy and wrap just the processing and use the draft BatchMessageListenerContainer, subclassing to add the retry. Maybe you could even re-use the ItemReaderRetryPolicy there as well.

Comment

Hi,
I'm facing a problem with using BatchMessageListenerContainer.
When an exception occurs in the the onMessage() call; it goes outside the repeat template but is not caught inside a loop in which the receieveAndExecute() can happen again.
In the following code (from DefaultMessageListenerContainer$AsyncMessageListen erInvoker.run), shouldn't there be a try/catch inside the while-loop surrounding the invokeListener() ? A similar thing happens in ExternalRetryInBatchTests.

When an exception occurs in my "processor" (onMessage()) the control just comes out and no retry occurs.

Following is the stacktrace of the exception:

Code:

at mypkg.transport.jms.JMSServer$JmsListener.onMessage(JMSServer.java:246)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:506)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:463)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:435)
at org.springframework.batch.container.jms.BatchMessageListenerContainer.doExecuteListener(BatchMessageListenerContainer.java:103)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:316)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:255)
at org.springframework.batch.container.jms.BatchMessageListenerContainer.doBatchCallBack(BatchMessageListenerContainer.java:197)
at org.springframework.batch.container.jms.BatchMessageListenerContainer$1.doInIteration(BatchMessageListenerContainer.java:157)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:324)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:211)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:142)
at org.springframework.batch.container.jms.BatchMessageListenerContainer.receiveAndExecute(BatchMessageListenerContainer.java:155)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:927)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:851)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: MsgCallback
at mypkg.transport.jms.JMSServerTest$3.messageCallback(JMSServerTest.java:100)
at mypkg.transport.jms.JMSServer$JMSAbstractItemWriter.write(JMSServer.java:287)
at org.springframework.batch.retry.callback.ItemReaderRetryCallback.process(ItemReaderRetryCallback.java:127)
at org.springframework.batch.retry.callback.ItemReaderRetryCallback.doWithRetry(ItemReaderRetryCallback.java:100)
at org.springframework.batch.retry.support.RetryTemplate.execute(RetryTemplate.java:168)
at mypkg.transport.jms.JMSServer$JmsListener.onMessage(JMSServer.java:244)