一、前言

关于2PC的理论知识请见:分布式_理论_03_2PC

这一节我们来看下github上一个优秀的2PC分布式事务开源框架的快速体验。

二、源码

源码请见:

https://github.com/yu199195/Raincat

相关视频

http://www.iqiyi.com/u/1243078745/v

三、接入步骤

1.启动 TxManagerApplication

此工程为分布式事务的协调者

  • 配置txManaager, 修改application.properties中你自己的redis配置
  • 启动TxManagerApplication

2.引入依赖

在需要进行分布式事务处理的服务的pom.xml中引入如下依赖:

   <dependency>
<groupId>com.raincat</groupId>
<artifactId>raincat-springcloud</artifactId>
<version>${your.version}</version>
</dependency>

3.配置文件

(1)新建applicationContext.xml,增加如下配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
default-autowire="byName"> <context:component-scan base-package="com.raincat.*"/>
<aop:aspectj-autoproxy expose-proxy="true"/>
<bean id="txTransactionBootstrap" class="com.raincat.core.bootstrap.TxTransactionBootstrap">
<property name="txManagerUrl" value="http://localhost:8761"/>
<property name="serializer" value="kryo"/>
<property name="nettySerializer" value="kryo"/>
<property name="compensationCacheType" value="db"/>
<property name="compensation" value="true"/>
<property name="txDbConfig">
<bean class="com.raincat.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://localhost:3306/tx?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
</property> </bean> <!--
<property name="compensationCacheType" value="db"/>
<property name="txDbConfig">
<bean class="com.raincat.common.config.TxDbConfig">
<property name="url"
value="jdbc:mysql://192.168.1.68:3306/alipay?useUnicode=true&amp;characterEncoding=utf8"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="password" value="Wgj@555888"/>
<property name="username" value="xiaoyu"/>
</bean>
</property> <property name="compensationCacheType" value="redis"/>
<property name="txRedisConfig">
<bean class="com.raincat.common.config.TxRedisConfig">
<property name="hostName"
value="192.168.1.78"/>
<property name="port" value="6379"/>
<property name="password" value=""/>
</bean>
</property> <property name="compensationCacheType" value="zookeeper"/>
<property name="txZookeeperConfig">
<bean class="com.raincat.common.config.TxZookeeperConfig">
<property name="host" value="192.168.1.132:2181"/>
<property name="sessionTimeOut" value="100000"/>
<property name="rootPath" value="/tx"/>
</bean>
</property> <property name="compensationCacheType" value="mongodb"/>
<property name="txMongoConfig">
<bean class="com.raincat.common.config.TxMongoConfig">
<property name="mongoDbUrl" value="192.168.1.78:27017"/>
<property name="mongoDbName" value="happylife"/>
<property name="mongoUserName" value="xiaoyu"/>
<property name="mongoUserPwd" value="123456"/>
</bean>
</property> <property name="compensationCacheType" value="file"/>
<property name="txFileConfig">
<bean class="com.raincat.common.config.TxFileConfig">
<property name="path" value=""/>
<property name="prefix" value="tx"/>
</bean>
</property> --> </beans>

将协调者的地址 以及 事务补偿数据库链接配置成正确的

(2)然后在启动类上增加如下注解,以配置生效

@ImportResource({"classpath:applicationContext.xml"})

4.分布式事务处理

在需要进行分布式事务处理的接口上,增加如下注解:

@TxTransaction

四、启动demo示例

作者提供了示例工程,以便使用者能快速体验raincat。

地址见:

quick start (springcloud)

1.clone & build

打开git bash 运行如下命令

git clone git@github.com:yu199195/Raincat.git
cd Raincat
mvn -DskipTests clean install -U

2.启动TxManagerApplication

此工程为分布式事务的协调者

  • 配置txManaager, 修改application.properties中你自己的redis配置
  • 启动TxManagerApplication

3.引入依赖包(sample已经引入)

   <dependency>
<groupId>com.raincat</groupId>
<artifactId>raincat-springcloud</artifactId>
<version>${your.version}</version>
</dependency>

4.数据库准备

执行 raincat-springcloud-sample 工程 sql文件 springcloud-sample.sql

5.配置文件

(1)在每个工程下 application.yml 中配置您的数据库连接(只需要改ip和端口)

(2)在每个工程下 applicationContext.xml中的TxDbConfig 配置您的补偿数据库连接,提供单独的数据库来存储。

6. @TxTransaction

在需要做分布式事务的接口上加上注解 @TxTransaction (sample已经加上)

7.启动服务

依次启动

  • AliPayApplication
  • WechatApplication
  • PayApplication

8.体验测试

访问API接口列表,进行体验测试

http://localhost:8881/pay-service/swagger-ui.html

分布式事务_01_2PC框架raincat快速体验的更多相关文章

  1. 分布式_事务_01_2PC框架raincat快速体验1

    一.前言 关于2PC的理论知识请见:分布式_理论_03_2PC 这一节我们来看下github上一个优秀的2PC分布式事务开源框架的快速体验. 二.源码 源码请见: https://github.com ...

  2. 分布式事务_03_2PC框架raincat源码解析-事务提交过程

    一.前言 前面两节,我们已经将raincat的demo工程启动,并简单分析了下事务协调者与事务参与者的启动过程. 这一节,我们来看下raincat的事务提交过程. 二.事务提交过程概览 1.二阶段对应 ...

  3. 分布式事务_02_2PC框架raincat源码解析-启动过程

    一.前言 上一节已经将raincat demo工程运行起来了,这一节来分析下raincat启动过程的源码 主要包括: 事务协调者启动过程 事务参与者启动过程 二.协调者启动过程 主要就是在启动类中通过 ...

  4. Hmily:高性能异步分布式事务TCC框架

    Hmily框架特性 无缝集成Spring,Spring boot start. 无缝集成Dubbo,SpringCloud,Motan等rpc框架. 多种事务日志的存储方式(redis,mongdb, ...

  5. 分布式_事务_02_2PC框架raincat源码解析

    一.前言 上一节已经将raincat demo工程运行起来了,这一节来分析下raincat的源码 二.协调者启动过程 主要就是在启动类中通过如下代码来启动 netty nettyService.sta ...

  6. 高性能异步分布式事务TCC框架(资料汇总)

    https://github.com/yu199195/hmily tcc源码解析系列(一)之项目结构 https://yu199195.github.io/2017/10/11/TCC/tcc-on ...

  7. 分布式事务专题笔记(一) 基础概念 与 CAP 理论

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.基础概念 1.什么是事务 什么是事务?举个生活中的例子:你去小卖铺买东西,“一手交钱,一手交货”就是 ...

  8. Album++:分布式事务专辑-基础概念

    (一)基础概念:↓ ↓ ↓ 1.1)什么是事务 什么是事务?举个生活中的例子:你去小卖铺买东西,"一手交钱,一手交货"就是一个事务的例子,交钱和交货必 须全部成功, 事务才算成功, ...

  9. Spring Cloud Alibaba分布式事务组件 seata 详解(小白都能看懂)

    一,什么是事务(本地事务)? 指作为单个逻辑工作单元执行的一系列操作,要么完全地执行,要么完全地不执行. 简单的说,事务就是并发控制的单位,是用户定义的一个操作序列.      而一个逻辑工作单元要成 ...

随机推荐

  1. app是什么意思?智能手机的第三方应用程序

    APP,在手机中的意思就是application的简称,也就是应用程序的意思,一般指手机软件,是安装在手机上的软件,完善原始系统的不足与个性化.APP是智能手机的第三方应用程序,app通常分为个人用户 ...

  2. mysql启动报错“NET HELPMSG 3534“的解决办法

    原因: mysql安装步骤错误,从mysql5.7.6开始,mysql需要这样安装: mysqld --initialize-insecure或者mysqld --initialize mysqld ...

  3. python基础27 -----python进程终结篇-----IO模型

    一.IO模型 1.IO模型分类 1.阻塞IO--------blocking IO 2.非阻塞IO------nonblocking IO 3. 多路复用IO------- multiplexing ...

  4. 剑指offer面试54题

    面试54题: 题目:二叉搜索树的第K大节点 题:给定一颗二叉搜索树,请找出其中的第k小的结点.例如, 5 / \ 3 7 /\ /\ 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4. 解题思 ...

  5. [转]c#中从string数组转换到int数组

    string[] input = { "1", "2", "3", "4", "5", " ...

  6. MYSQL:基础—主键

    MYSQL:基础—主键 1.什么是主键 表中的每一行都应该具有可以唯一标识自己的一列(或一组列).而这个承担标识作用的列称为主键. 如果没有主键,数据的管理将会十分混乱.比如会存在多条一模一样的记录, ...

  7. bacula 备份恢复

    一.数据恢复: 在bacula服务器执行: /opt/bacula/etc/ bconsole #进入交互窗口 *restore #输入restore恢复命令 Automatically select ...

  8. Centos 常用系统命令

    一.查看系统硬件信息: 1.CPU # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 c ...

  9. 算法寒假实习面试经过之 滴滴(电话一面二面 offer)

    一面:1h 介绍比赛项目. lr与xgb的区别? xgb 为什么不用归一化,onehot? xgb 与 gbdt的区别. 做这些比赛你们的优势在哪,既然全是相同的套路. RCNN的原理, CNN的原理 ...

  10. 深入浅出Node.js(上)

    (一):什么是Node.js Node.js从2009年诞生至今,已经发展了两年有余,其成长的速度有目共睹.从在github的访问量超过Rails,到去年底Node.jsS创始人Ryan Dalh加盟 ...