Avatar billede fredand Forsker
03. april 2008 - 10:16 Der er 2 kommentarer og
1 løsning

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
Avatar billede lborupj Nybegynder
03. april 2008 - 20:04 #1
Hi Fredrik,

You cannot use Bean Managed Transaction BMT and MDB's and expect a RuntimeException (or setRollbackOnly) to span the MQ resources and hence acknowledgement of messages. If you use BMT, acknowledgement of received messages are handled out-side the scope of the onMessage (and UserTransaction), so its basically not possible to get the message redelivered. You have to go CMT to get this to work, but remember to include MQ in a 2PC transaction, you have to use the client extension from IBM, otherwise you might want to use a MessageBridge (in BEA) to move the message from MQ to a local JMS queue, and let that take part in a transaction.

Cheers, Lars Borup Jensen
http://www.it-arbejde.dk
Avatar billede fredand Forsker
29. december 2010 - 21:17 #2
Hello Lars!

Please leave a svar so I can reward you!

Btw, thanks for a great explanation!

/Fredrik
Avatar billede lborupj Nybegynder
30. december 2010 - 17:32 #3
Hi Fredrik,

Sure - here you go!

Regards, Lars Borup
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester