I've got a quite simple scenario including a database along with a JMS within an application server (Glassfish). The scenario is dead simple:
1. an EJB inserts a row in the database and sends a message. 2. when the message is delivered with an MDB, the row is read and updated.
However , sometimes the message is shipped prior to the place continues to be committed within the database. This really is really understandable when we think about the 2 phase commit protocol:
1. prepare JMS 2. prepare database 3. commit JMS 4. ( tiny little gap where message can be delivered before insert has been committed) 5. commit database
I have talked about this issue with others, however the answer was always: "Strange, it will work as they areInch.
My questions are then:
- How could it exercise-of-this area?
- My scenario sounds quite simple, why is not there more and more people concentrating on the same troubles?
- Shall We Be Held doing a problem? It is possible to method to solve this problem properly?
Listed here are a little more particulars about my knowledge of the issue:
This timing problem exist only when the participant are treated within this order. When the 2PC goodies the participants within the reverse order (database first then message broker) that needs to be fine. The issue was at random happening but completely reproducible.
I discovered not a way to manage an order from the participants within the distributed transactions within the JTA, JCA and JPA specifications neither within the Glassfish documentation. We're able to assume they'll be enlisted within the distributed transaction based on the order when they're used, however with an ORM for example JPA, it's tough to understand once the data are flushed so when the database connection is actually used. Any idea?
You're going through the classic XA 2-PC race condition. It will take place in production conditions.
You will find 3 things visiting my thoughts.
- Last agent optimisation where JDBC may be the non-XA resource.(Lose recovery semantics)
- Have JMS Time-To-Deliver. (Delibrately Lose real-time)
- Build retries into JDBC code. (Least impact on fuctionality)
Weblogic has this LLR optimisation eliminates this issue and provides all of you XA gaurantees.