浅尝分布式事务

理论学习:

  DTP:DTP全称是Distributed Transaction Process,即分布式事务模型。主要涉及了三个对象:       

      AP(Application Program):应用程序

      TM(Transaction Manager):事务管理器。负责协调和管理事务

      RM(Resource Manager):资源管理器。可以理解为数据库或者JMS。

  他们三者的关系:

     AP通过TM来操作多个RM,AP也可以通过RM的本地事务接口来操作单个RM

     TM和RM可以互相通信,他们之前的通信协议就是XA协议

 

   TA:This is the interface between theTM and the RM in an X/Open DTP system.The X/Open DTP model envisages interfaces between each of the AP, RM, and TM.Generally, each use of the XA interface is prompted by the AP calling the TM or the RM.

   

          XA是由X/Open组织提出的分布式事务的规范。XA规范主要定义了(全局)事务管理器(Transaction Manager)和(局部)资源管理器(Resource Manager)之间的接口。XA接口是双向的系统接口,在事务管理器(Transaction Manager)以及一个或多个资源管理器(Resource Manager)之间形成通信桥梁。XA之所以需要引入事务管理器是因为,在分布式系统中,从理论上讲(参考Fischer等的论文),两台机器理论上无法达到一致的状态,需要引入一个单点进行协调。事务管理器控制着全局事务,管理事务生命周期,并协调资源。资源管理器负责控制和管理实际资源(如数据库或JMS队列)。

        JTA:JTA (Java Transaction API) defines the interfaces for Java applications to interact with the platform-specific transaction manager. Like most APIs in Java, JTA allows for different implementations that offer the same interface towards the application. This implies that you can write transactional Java applications that do not depend on any particular transaction manager vendor (if you adhere to the API that is). Some vendors like Atomikos® offer their implementation in open source, whereas other vendors (like IBM) offer an implementation as part of their application server.

        作为Java平台上事务规范JTA(Java Transaction API)也定义了对XA事务的支持,实际上,JTA是基于XA架构上建模的,在JTA 中,事务管理器抽象为javax.transaction.TransactionManager接口,并通过底层事务服务(即JTS)实现.

主要2个大包的内容:

   javax.transaction

   javax.transaction.xa 

 AP:我们的应用程序

 TM:即javax.transaction.TransactionManager 事务管理器 

 RM:即javax.transaction.xa.XAResource 我称之为与资源管理器的一个通信代表,我们通过XAResource接口方法和资源管理器进行通信

Atomikos:

Atomikos TransactionsEssentials's documentation and literature on the internet show that it is a production quality implementation, which also supports recovery and some exotic features beyond the JTA API. Atomikos provides out-of-the-box Spring integration along with some nice examples. It also provides support for pooled connections for both database and JMS resources.


附上我这两天写的一个小demo







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值