Even when putting:
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
on the onMessage method of an MDB a transaction is still started. This can be verified by using a simple MDB that sleeps for longer than the transaction timeout (300 seconds by default). For example:
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.Message;
import javax.jms.MessageListener;
import org.apache.log4j.Logger;
@MessageDriven(activationConfig =
{ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/A"), @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "3") })
public class ExampleEJB3MDB implements MessageListener {
private static final Logger logger = Logger.getLogger(ExampleEJB3MDB.class);
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void onMessage(Message m) {
logger.info("message received, waiting for 10 mins...");
try
{ Thread.sleep(600000); // 10 mins } catch (InterruptedException e) {
}
logger.info("finished waiting");
}
}
When a message is sent to "queue/A" and the MDB picks it up it prints "message received, waiting for 10 mins..." in the log. After 5 minutes (300 seconds) the message appears in the log again because the transaction has timed-out and the message has been redelivered.
I believe the problem lies in org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory in the isDeliveryTransacted method. Here is that method [1]:
public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException
{
TransactionManagementType mtype = TxUtil.getTransactionManagementType(container);
if (mtype == javax.ejb.TransactionManagementType.BEAN) return false;
TransactionAttribute attr = (TransactionAttribute)container.resolveAnnotation(method, TransactionAttribute.class);
if (attr == null)
TransactionAttributeType type = TransactionAttributeType.REQUIRED;
if (attr != null) type = attr.value();
return type == javax.ejb.TransactionAttributeType.REQUIRED;
}
It seems there should be an explicit check for TransactionAttributeType.NOT_SUPPORTED. If the MDB uses @TransactionManagement(TransactionManagementType.BEAN) then the redelivery doesn't occur (since the code explicitly checks this attribute and returns false if it is present).
- blocks
-
JBPAPP-1668 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) ignored on MDB onMessage
- Closed