I have the following MessageDrivenBean:
@MessageDriven(mappedName = "jms/...", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryAttempts", propertyValue = "5"), @ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryInterval", propertyValue = "1000") }) public class MyMessageListener implements MessageListener { @Resource private MessageDrivenContext context; @Override @TransactionAttribute(REQUIRED) public void onMessage(Message message) { } }
Inside the onMessage method, I do some processing, which is not important here. In certain situations, I want to refuse processing. In such situations, I want to mark the transaction as a rollback only and do not want to repeat the processing.
At least on Glassfish 3.1.1, if I call context.setRollbackOnly() on MessageDrivenContext and finish processing without throwing an exception, the message overflows at infinitely very, very short intervals. So this is not an option for me.
If I throw a RuntimeException , the message will be re-added as I pointed it out. It is reinstalled 5 times with an interval of 1 second. But in my case, I donβt want to repeat the processing at all.
If I just finish processing without raising any exception and not calling context.setRollbackOnly() , the transaction is committed as expected. But I need to cancel the transaction, because I may have already changed some JPA entities.
I have a question: how can I mark a transaction as rollback only after sending additional message delivery?
source share