JTA Transaction multiplexing
jms_j Apr 14, 2009 8:50 AMHi,
I currently have a need to have multiple database connections ( to the same database instance ) to participate in a single transaction. From what I have gathered, I actually need JTA transaction mutiplexing:
1) See the subection "Multiplexing" in this link:
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzaha/distrans.htm
2) Followed by an example code:
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzaha/JTAMultiConn.htm
Backpedal a bit: I have a list of objects that I need to perform operations on. Currently, code is sequentially iterating through the list and perform the operation one at a time. I would like to run the operations concurrently, since each one is really indepedent of the other. However, all of them MUST participate in a single transaction.
It is somewhat like this:
A) Debit money from a single entity
B) Credit money to N entities, where N could be anywhere from 1 to tens of thousands.
All of this on a single database instance.
At the moment, the crediting of the money is done sequentially, but I would like to do them concurrently, as each receiving entity is really independent of the other receiving entities. However, all of these must be done in a single transaction.
Options:
O1) Can't create threads, as this will be done inside a J2EE container.
O2) Process the receiving entities concurrently via a JMS queue/ via a message-driven bean ( MDB ). .. but each receiver on that queue must "know" the transaction that is must join with / to. If all entities received the money without problem, then a commit can be made. This commit will therefore need to be made by the code that sent all the messages / entities into the JMS queue. Thus, each MDB, do not really commit, but could rollback if the money could not be credited to a single entity.
Even though it is all done on a single database instance, I will still need XA capability as transaction multiplexing can only be done via XA.
So using the sample code from IBM, I was trying to write some test code that will:
T1) Create 2 XA connections from the same XA datasource, and have the 2 connections "join" a single transaction ... all on a single thread / JVM.
T2) If above works, then write some MDB code that will obtain an XA connection from an XA datasource, "join" the connection to a pre-determined transaction Xid. The Xid would have been created by the code that sent the messages into the JMS queue, and it is that code ( the one that sent the messages into the JMS queue ) that will commit the transaction.
However, I am having trouble modifying the code to work with JBoss:
P1) All datasources and connections obtained via JNDI from JBoss are all "wrapper" ( e.g. WrappedDataSource, WrappedConnection, etc.. ). Thus, the corresponding XA methods are not available. For example, I could not call DataSourc e.getXAConnection(), or XAConnection.getXAResource() because of the wrapping.
P2) How do I obtain an Xid with JBoss ? ... so that I can pass the Xid as part of the message into a JMS queue ?
Last but not the least, even though there are 3 nodes in our JBoss cluster, I don't need a clustered post-office for this queue. In fact, I don't want a clustered post-office for this queue ONLY, to remove potential issues with a "clustered" transaction manager ( since I am passing the Xid into the JMS queue ). I know that a non-clustered post-office is possible, so that is really not an issue.
Any help appreciated.