I need to redeliver a message if it can't be processed, for example because of some external endpoint failure. So I'm using following MDB configuration (it worth to mention that I'm using openMQ (Glassfish 4.1)):
@MessageDriven(mappedName = "MyQueue", name = "MyQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryAttempts", propertyValue = "10"),
@ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryInterval", propertyValue = "30000")})
Here's onMessage() method:
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void onMessage (Message message)
{
try
{
//some processing here
}
catch (JMSException jmsException)
{
logger.log (Level.SEVERE, "Exception processing notification message", jmsException);
}
catch (BackingStoreException e)
{
// because of throwing RuntimeException, the message is going to be redelivered according to mdb configuration params(interval and attempts count)
throw new RuntimeException ();
}
}
In order to redeliver a message it's also possible to rollback a transaction, however openMQ lacks the property for redelivery interval, so it doesn't suites me:
https://github.com/javaee/openmq/issues/220
https://github.com/javaee/openmq/issues/23
https://github.com/javaee/openmq/issues/134
All in all, redelivery works fine, besides one moment: if message is going to be redelivered, mdb doesn't release the connection and holds it for endpointExceptionRedeliveryInterval * endpointExceptionRedeliveryAttempts, in my case 5 minutes. So, cause the default values for maxPoolSize is 32, 32 "bad" messages are enough to block the mdb.
Is there are way to release the connection in case of message redelivering?