ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Why does not my Exception make a rollback?

Post new topic  Reply to topic
 Why does not my Exception make a rollback? « View previous topic :: View next topic » 
Author Message
fredand44
PostPosted: Thu Apr 03, 2008 12:01 am    Post subject: Why does not my Exception make a rollback? Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Thu Apr 03, 2008 1:47 am    Post subject: Reply with quote

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
View user's profile Send private message
fredand44
PostPosted: Thu Apr 03, 2008 2:41 am    Post subject: Acctually it is version 6.0! Reply with quote

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
View user's profile Send private message
JLRowe
PostPosted: Thu Apr 03, 2008 7:42 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
fredand44
PostPosted: Thu Apr 03, 2008 9:07 am    Post subject: I do not think that would work. Reply with quote

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
View user's profile Send private message
JLRowe
PostPosted: Fri Apr 04, 2008 1:29 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Fri Apr 04, 2008 2:48 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Why does not my Exception make a rollback?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.