且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何设计全局分布式事务(无数据库)? JTA可以用于无数据库事务吗?

更新时间:2023-02-02 21:27:24

你是的,由于JTA API提供的XA事务管理器,您需要两阶段提交支持。

You're right, you need two-phase commit support thanks to a XA transaction manager provided by the JTA API.

据我所知Spring没有提供事务管理器实施本身。 JtaTransactionManager 通常仅委托现有实施从JavaEE实现提供。

As far as I know Spring does not provide a transaction manager implementation itself. The JtaTransactionManager only delegates to existing implementation usually provided from JavaEE implementations.

因此,您必须将JTA实现插入Spring才能完成有效的工作。以下是一些建议:

So you will have to plugin a JTA implementation into Spring to get effective job done. Here are some proposals:

  • JOTM
  • JBossTS based on Arjuna.
  • Atokimos

然后,您必须实现资源管理器以支持两阶段提交。在JavaEE世界中,它包含一个打包为RAR存档的资源适配器。根据资源的类型,以下几个方面是阅读/实现:

Then you will have to implement your resource manager to support two-phase commit. In the JavaEE worlds, it consists in a resource adapter packaged as a RAR archive. Depending on the type of resource, the following aspects are to read/implement:

  • XAResource interface
  • JCA Java Connector Architecture mainly if a remote connection is involved
  • JTS Transaction Service if transaction propagation between nodes is required

作为示例,我建议您查看经典的带文件交易问题的实现:

As examples, I recommend you to look at implementations for the classical "transactions with files" issue:

  • the transactional file manager from JBoss Transactions
  • XADisk project