How do I limit the amount of times a JMS DefaultMessageListenerContainer will retry a message?

Jose picture Jose · May 11, 2012 · Viewed 8.3k times · Source

I am using Spring JMS to connect to a Websphere MQ server. I implemented the SessionAwareListener interface to create a custom listener, reusing old code for the business logic.

While testing, the listener throws a StringIndexOutOfBoundsException, which I fail to catch. However, I see in the log the following printed about 32 times, then the DMLC stops.

WARN  - Execution of JMS message listener failed

Is there a way to control how often the DMLC will retry a message, and how to handle uncaught exceptions?

Answer

DaTroop picture DaTroop · May 11, 2012

You can always check the JMSDeliveryCount. If it is more than the number you consider as maximum then just don't process the message and return.

You can also configure your Websphere to move the bad message to the exception destination after some attempts.