浅尝分布式事务

来源:互联网 发布:苹果一体机数据恢复 编辑:程序博客网 时间:2024/06/06 01:07

理论学习:

  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







原创粉丝点击