Duncan
Duncan

Reputation: 527

How to implement distributed end-to-end transactions with JMS

I need to implement a transaction that spans applications running on different systems and communicating via JMS. Actually, I don't need to implement it yet, at this point I just need a high level design with some confidence that it can be implemented.

Here's what I need to do.

Assume I have two applications (running on different servers) that are maintaining some state information that must be kept consistent. For simplicity, let's say they are both keeping track of the value of a single variable X.

I need the sending application to do the following:

The receiver has to do something similar, and the whole thing has to be "transactional" in the sense that I need high confidence that both systems have the same value of X, changed or not, within some fixed time interval. I can afford rare cases where things break down, as long as the software on at least one end knows that things have run amok and can alert the operator that the value of X may be inconsistent.

At first I thought this would be relatively easy using the features of JMS. But after doing a bunch of reading about JMS, now I don't think so. There are some complications, in particular:

I read up on how JMS acknowledgements work, the different acknowledgement modes, and using JMS transactions. Tell me if I'm wrong, but I don't think any of this is going solve my problem. These features may allow me to handle any errors that would occur in getting my message gets delivered from my app to the JMS broker, but:

So then I started reading up on Distributed Transaction Processing and XA. In theory, I think this is what I need. A single transaction manager and a 2-phase commit protocol. However, this is not something that is feasible to implement myself, I would need to use an off-the-shelf solution. So I'm reading up on JTA, but I'm still struggling to understand the concepts. It seems that JTA allows me, from one application, to have a single transaction that involves a bunch of different operations, e.g. send a JMS message, write data to a database, etc... If each of these things has an XA compliant "resource manager" then I can put them all together into a single transaction (everthing will happen, or it will all get rolled back) from my one application using JTA.

But I'm struggling to see how I can use that. I don't have one application, I have two. And I don't have an XA compliant resource manager for these applications. Would I have to write one? Somehow use an application that does (e.g. a database)?

Any suggestions?

Thanks and sorry for the newbie questions!

Duncan

Upvotes: 2

Views: 361

Answers (1)

Petter Nordlander
Petter Nordlander

Reputation: 22279

Transactions, even distributed transactions, often just makes sure some messages get written to queue, read from a queue or a message processing commits at the same time as some database operation. It won't solve your problem unless you add a lot of complexity.

Your problem looks like a data synchronization problem over multiple systems. I recommend looking at some other way to handle that synchronization.

One common approach is to write the latest update of some value (price?) to a JMS topic together with some timestamp (or other information to consider if this information is valid). Then all systems can keep up with the latest information (and safely reject publications with "out-of-date" information). Can something similar solve your case?

If your different systems have different underlying databases, you can of course use XA transactions (there are open source XA transaction managers around) and commit the new value X to both databases. This will be "safe", but on the other hand, it will keep your system tightly coupled, which often is not a good idea.

Upvotes: 1

Related Questions