I am trying to understand the basic principles of creating a remote / network resource compatible with JTA, and I am amazed at how little documentation / blogs / articles there are on this subject.
Let's say I wrote my own special server, the server "IAmYourFaja" or " IAYF ". And let me say that I wrote / implemented my own TCP protocol for interacting with this server called IAYFCP (IAYF Comms Protocol). Finally, I wrote a Java client library to access and send messages to a remote IAYF server through IAYFCP. Still with me?
Now I have a use case when I need to execute the following distributed transaction:
- Insert a record into a relational / JDBC database; then
- Leave a message on my IAYF server; then
- Click Message to JMS Browser
I need all of them to be executed so that if any one component fails at any time, I can drop them all back and not have any changed state in these network resources.
The ultimate goal would be to run the following code (pseudocode here):
DistributedTransaction dTrans = getTransaction();
DataSource jdbcDataSource = getDataSource();
IayfClient iayfClient = getIayfClient();
JmsClient jmsClient = getJmsClient();
try {
dTrans.begin();
insertRecord(jdbcDataSource, "INSERT INTO widgets ( fizz, buzz ) VALUES ( 35, true )");
iayfClient.fireMessage(IayfMessages.LukeIamYourFaja, 12);
jmsClient.publishMessage("Noooooooooo! (then jumps off ledge and Vader goes off to the bar)");
dTrans.commit();
} catch(Throwable t) {
dTrans.rollback();
}
So, the JDBC driver and the JMS library that I use are already compatible with JTA. This means that in order to make this code possible, I need to make my IAYF client library also compatible with JTA. The problem is that I don’t understand which JTA interfaces I need to implement:
So a few questions:
- What I need to implement an interface (and why)
XAResource, UserTransactionor both? - , , JTA IAYF / ? - , , "JTA Example" , ?
- . Java EE , , , - Java EE/JTA- , - Bitronix Atomikos, ?