Why does my Exception not make a rollback?
Hello!I got an MDB registred in a WLS 8.1.5 that consumes messages from a queue in my MQ 5.3.
I use Bean-manged-transaction for the MDB, and the code/logic looks like:
onMessage(Message m)
{
UserTransaction userTransaction = context.getUserTransaction();
try
{
userTransaction.begin();
//Exception test
if(1==1)
{
throw new Exception("Testing rollback");
}
userTransaction.commit();
catch(Exception e)
{
e.printStackTrace();
try
{
userTransaction.setRollbackOnly();
userTransaction.rollback();
}
catch (Exception e2)
{
e2.printStackTrace();
}
//Exception below should rollback onMessage
throw new RuntimeException();
}
}
What I expected to happen was that when a message arrives at my queue in MQ the MDB start to consume it.
But when the RuntimeException is thrown, the onMessage will not reurn succesfully.
Then the message should not have been consumed and should remain at the queue in MQ?
But when I try the message gets consumed and disappear.
Any comments is most welcome.
My mdb-tag in ejb-jar.xml looks like
<message-driven >
<ejb-name>MqMDB</ejb-name>
<ejb-class>mytest.MqMDB</ejb-class>
<transaction-type>Bean</transaction-type>
<acknowledge-mode>Auto-acknowledge</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
<subscription-durability>NonDurable</subscription-durability>
</message-driven-destination>
</message-driven>
My mdb-tag in weblogic-ejb-jar.xml looks like
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>MqMDB</ejb-name>
<message-driven-descriptor>
<pool>
<max-beans-in-free-pool>1</max-beans-in-free-pool>
<initial-beans-in-free-pool>1</initial-beans-in-free-pool>
</pool>
<destination-jndi-name>SP.BRKQM01.RES.L</destination-jndi-name>
<initial-context-factory>com.sun.jndi.fscontext.RefFSContextFactory</initial-context-factory>
<provider-url>file:/C:/testjndi</provider-url>
<connection-factory-jndi-name>queue.connection.factory</connection-factory-jndi-name>
<jms-polling-interval-seconds>10</jms-polling-interval-seconds>
</message-driven-descriptor>
<reference-descriptor>
</reference-descriptor>
</weblogic-enterprise-bean>
Best regards
Fredrik
