7

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?

Jose
  • 1,616
  • 4
  • 26
  • 38
  • So u r using the IBM MQ JCA adapter right? Where is your Spring application deployed? – Timmo May 11 '12 at 13:56
  • No we are only using Websphere MQ, not the application server. The Spring application is a standalone JVM. – Jose May 11 '12 at 14:08

2 Answers2

5

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.

Timmo
  • 3,142
  • 4
  • 26
  • 43
  • Thanks for the article. That helped to see what was happening on the backend. I'm now using the JMSXDeliveryCount and JMSRedelivered JMS properties to handle the message. – Jose May 11 '12 at 14:25
  • Do you happen to know anything in the Spring API that could also help in error handling? – Jose May 11 '12 at 14:26
  • Unfortunately I don't know much about Spring my friend. – Timmo May 11 '12 at 14:29
  • Lol no worries. I'm trying to figure it out myself. But using Spring has removed a lot of boiler-plate code. All I had to do was define the MessageListener. Worth learning IMO. – Jose May 11 '12 at 15:00
  • I've always used plain JEE and I am quite happy with it – Timmo May 11 '12 at 17:38
5

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.

Matej
  • 6,004
  • 2
  • 28
  • 27
  • Thanks for the response! Yours in conjuntion with DaTroop helped in solving the problem. – Jose May 11 '12 at 14:27
  • On 1, the MQ properties are BOTHRESH for the retry limit, and BOQNAME for the queue where the message will be forwarded once that retry limit is reached. – Jose Gómez Jul 06 '15 at 14:03