Menu

Messaging Queue – Handling Errors

One of the outstanding actions from that post was to investigate how to handle errors, and effectively stop the processing of messages so the fault could be investigated.

I found that handling any JMSExceptions and introducing a MessageDrivenContext object allowed me to set the message for rollback. This had the effect of placing the current message back on the queue stack. Unfortunately with GlassFish this then seemed to enter an infinite loop of receiving the message, throwing the exception, placing the message back in the queue… receiving the message… and so on…

The recommended practice to prevent this behaviour seemed to surround setting an ActivationConfigProperty, namely endpointExceptionRedeliveryAttempts. However I couldn’t get this working on GlassFish at all. There were many Google results, albeit from a couple of years ago, with people facing similar issues. One of these results recommended a horribly solution of sleeping the bean processing for a period of time before trying again, which is the wart-and-all solution I’ve gone for at the moment. I’ll return to investigate this issue further!

So the source code for the MessageBean implementation now looks as follows: