Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jms

ibm-mq

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?

like image 442
Jose Avatar asked May 11 '12 13:05

Jose


2 Answers

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.

like image 151
Timmo Avatar answered Nov 03 '22 00:11

Timmo


Putting back a message to the queue after some error is called backout in the Websphere MQ world.

There are two alternatives how to handle it:

  1. In the queue manager: You can configure backout threshold and backout requeue name properties for the given queue. After backout treshold is reached, queue manager will put the message to the queue specified by the backout requeue name instead of redelivering it. See WebSphere MQ queue properties for more information.

  2. In your application: If you use JMS API, check the JMSXDeliveryCount property by calling msessage.getIntProperty("JMSXDeliveryCount") before you start processing the message. If it reaches some treshold, handle the message as errorneous.

like image 45
Matej Avatar answered Nov 03 '22 02:11

Matej