I was doing a MDB timeout test
1) I have a stls(ABean) bean and a mdb (BBean). BBean invokes ABean.
2) set @ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue = "10") to BBean
3) BBean will reply a message to a queue(replyQueue) at the end of onMessage(), if any exception throws, current message will fall to dlq.
4) ABean will sleep 20 seconds which will cause BBean timeout.
5) Redelivery Delay: 0, Max Delivery Attempts: 1
6) running on JBoss AS 7.1.0 final
Expect result is
Transaction timeout --> transaction rollback --> redelivery ---> transaction timeout again --->transaction rollback again ---> send message to dlq
Actual result is
Transaction timeout --> transaction rollback --> send message to dlq---> ABean and BBean keep running till ABean wake up --> reply message to replyQueue.
--->redeliver --> transaction timeout --> exception catch "The transaction is not active!" --->reply message to replyQueue
Seems the timeout just only rollback the tx transaction, but will not terminate the running thread or trigger redelivery.
Is there something wrong I have? Please help!! Many thanks!
Additional test result
After I set the Max Delivery Attempts to 3
I found that the exception message redeliver 3 times, all of them hit the same exception "Unable to call after delivery: javax.resource.spi.LocalTransactionException: javax.transaction.RollbackException: ARJUNA016063: The transaction is not active!", however each redeliver message replyed and only one dlq was added.
So I revised my above situation. Is this a bug?
So far I havn't found any elegent solution, however, I have a workaround, though it will introduces non-business code into your MDB.
1) Inject EJBContext to your MDB
2) Use ejbContext.getRollbackOnly() method to check whether the current transaction already rollback before continue process. If current transaction has been canceled, skip the following process till the end.
This solution should be safe in only database operating situation, meanwhile there still has a drawback for this solution. Please look at the following situation.
1) The some operations to a share resource which is not rollbackable, such as writing strings to a file in this transaction.
2) Redelivery Delay is 0 and Max Delivery Attempts more than 1
Once the transaction timeout, JMS will redeliver the message, but the previous message still on processing which is writing strings to a file. At this time, the file is operating by 2 threads and this may cause error. So it should be considered how to handle the resource conflict in this case.
Am I missing sth? please comment.