Author |
Message
|
fredand44 |
Posted: Thu Apr 03, 2008 12:01 am Post subject: Why does not my Exception make a rollback? |
|
|
Acolyte
Joined: 14 Feb 2006 Posts: 63
|
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.
Best regards
Fredrik |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Apr 03, 2008 1:47 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
V5.3 is out of support. Please Upgrade.
 _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fredand44 |
Posted: Thu Apr 03, 2008 2:41 am Post subject: Acctually it is version 6.0! |
|
|
Acolyte
Joined: 14 Feb 2006 Posts: 63
|
Hello!
Thanks for your reply.
Acctually I'm using version 6.0 in my development environment.
This is the place where I run in to this problem.
In our production environment we still got version 5.3. In this environment we will use 5.3 for at least 3 more months, so I will propably be forced to deploy my solution in such environment for some few months. I guess I will run into the same problems in 5.3.
Btw below is snippets from my ejb-jar.xml and weblogic-ejb-jar.xml
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>MyQueue</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 |
|
Back to top |
|
 |
JLRowe |
Posted: Thu Apr 03, 2008 7:42 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
Because you are using BMT, the message get and the work in the MDB will be in seperate transactions, the message get will always be committed by the container.
Change to using container managed transactions. |
|
Back to top |
|
 |
fredand44 |
Posted: Thu Apr 03, 2008 9:07 am Post subject: I do not think that would work. |
|
|
Acolyte
Joined: 14 Feb 2006 Posts: 63
|
Hello!
Thanks for your reply.
Sounds very interesting, but in our production environment the Weblogic and our MQ run on different machines.
Correct me if I'm wrong but even if we use CMT, then this architect can not support distributed transaction?
Please correct me if I'm wrong!!
(I hope I'm wrong!!)
Best regards
Fredrik |
|
Back to top |
|
 |
JLRowe |
Posted: Fri Apr 04, 2008 1:29 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
No, you have to use CMT, since the container starts the transaction for you, before it gets the message and passes it to the MDB. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Apr 04, 2008 2:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
If you want the exception to make a roll back you need to throw an MDB/EJB Exception or a JMSException and you cannot catch it.
This will propagate it to the container which will then roll back...
The easier thing is to do just as you have been told... Let the container manage the transaction.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|