开发者

JMS and JTA Transactions in Java EE

开发者 https://www.devze.com 2023-03-28 07:01 出处:网络
I think I am not getting something right with JMS and JTA. I am running in a Java EE container with all CMTs. Here is what I am doing:

I think I am not getting something right with JMS and JTA. I am running in a Java EE container with all CMTs. Here is what I am doing:

  1. In an SLSB, write something to the database
  2. From the same method of the SLSB, post a message to a JMS queue
  3. An MDB in the same container listens to the JMS queue and picks up the message
  4. The MDB reads the database

The problem is, the MDB does not see the changes made to the database in step 1.

I verified that steps 1 and 2 hap开发者_如何学Cpen inside a single XA transaction, as expected. My expectation is that a second XA transaction would start at step 3, after the first XA has been committed. But it seems that the MDB receives the message before the XA transaction that posted the message has been committed.

Is my expectation wrong and what I am seeing is normal?

I am running under JBoss 6. The SLSB is local. Both the SLSB and the MDB are in the same application.


I found the problem! My JMS connection factory was not XA aware. I had looked up /XAConnectionFactory for my JMS connection factory. In spite of the name, that's the wrong resource to lookup for a regular app in JBoss. There is a java:/XAConnectionFactory too, which does not work either. The correct resource name is java:/JmsXA. I used it and everything is working just as expected.

Thanks to @strmqm for nudging me to the right direction.


I saw a conceptually similar problem in an app built w/ WebLogic 7. The DB commit from tx1 wasn't complete by the time that tx2 (initiated by a JMS send in tx1) tried to read it.

The trouble there was that our configuration involved a WLS 7 XA emulation layer with a non-XA db connection (to Oracle DB). This risk was part of that XA shortcut. Apparently if we'd gone w/ the true XA all the way to the DB, that hole would have closed. Never ended up testing that.

You say this is JBoss. Any chance that they've got some similar shim that bypasses the XA and gives this same surprising result?

0

精彩评论

暂无评论...
验证码 换一张
取 消