How to limit the number of times the JMS DefaultMessageListenerContainer will repeat the message?

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

During testing, the listener throws a StringIndexOutOfBoundsException exception, which I cannot 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 repeat the message and how to handle uncaught exceptions?

+6
source share
2 answers

You can always check the JMSDeliveryCount. If it is more than the number that you consider to be the maximum, just do not process the message and do not return.

You can also customize your web page to move the bad message to the destination of the exception after some attempts.

+5
source

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

There are two options:

  • In the queue manager: you can configure the backup and backup threshold properties for this queue. After reaching equilibrium, the queue manager places the message in the queue indicated by the name of the backup request, instead of re-adding it. For more information, see WebSphere MQ Queue Properties .

  • In your application: if you use the JMS API, check the JMSXDeliveryCount property by calling msessage.getIntProperty ("JMSXDeliveryCount") before you start processing the message. If it reaches a certain level, treat the message as erroneous.

+5
source

Source: https://habr.com/ru/post/915503/


All Articles