-
1. Re: Why a message is not being redelivered
newway Aug 8, 2012 5:25 AM (in response to newway)same behavior also happens on jboss 4.2.3 with jboss messaging 1.4.5.GA - which probably points that the problem comes from my code - but i don't know where to start looking
-
2. Re: Why a message is not being redelivered
newway Aug 8, 2012 4:35 PM (in response to newway)Found the problem.
I have a base class that all the MDBs inherit from and one of the things it does is to wrap the onMessage method.
the wrapping looked like this:
try { process(message); } finally { destinationHandlerContainer.disconnectDestinationHandlers(); }
the problem was that when an exception was thrown is would have been caught by the messaging indfra and than return the execute the finally block.
so this fixes the problem:
try { process(message); } catch (Throwable t) { throw new RuntimeException(t); } finally { destinationHandlerContainer.disconnectDestinationHandlers(); }
-
3. Re: Why a message is not being redelivered
jbertram Aug 8, 2012 4:54 PM (in response to newway)1 of 1 people found this helpfulAccording to the JMS 1.1 specification (section 4.5.2) it isn't appropriate to throw a RuntimeException from onMessage():
A client can register an object that implements the JMS MessageListener interface with a MessageConsumer. As messages arrive for the consumer, the provider delivers them by calling the listener’s onMessage method.
It is possible for a listener to throw a RuntimeException; however, this is considered a client programming error. Well-behaved listeners should catch such exceptions and attempt to divert messages causing them to some form of application-specific 'unprocessable message' destination.
Furthermore, a RuntimeException thrown from any method of the message-driven bean class (including a message listener method and the callbacks invoked by the container) results in the transition to the 'does not exist' state. This means that the instance of the MDB has to be thrown away by the container and another has to be created.
At the end of the day you should just get the MessageDrivenContext and invoke setRollbackOnly() instead of throwing a RuntimeException. That should force redelivery as expected.
-
4. Re: Why a message is not being redelivered
newway Aug 9, 2012 3:29 AM (in response to jbertram)Thanks, I think you already explained that to me once before, hopefully I will not need this reminder in the future