# tcc-springcloud **Repository Path**: distransaction/tcc-springcloud ## Basic Information - **Project Name**: tcc-springcloud - **Description**: 通过tcc-transaction实现分布式事务,微服务通过springcloud实现。 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-23 - **Last Updated**: 2021-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # tcc-springcloud #### 介绍 通过tcc-transaction实现分布式事务,微服务通过springcloud实现。 #### 软件架构 SpringCloud微服务架构,为实现事务一致性,通过tcc-transaction实现tcc事务处理。 #### 安装教程 1. SpringCloud配置 查看SpringBoot与SpringCloud版本对应关系:https://start.spring.io/actuator/info 本项目采用SpringBoot:2.2.5.RELEASE,SpringCloud:Hoxton.SR10 2. 修改tcc-transaction源码tcc-transaction-core 修改ObjectSerializer类增加serializeObj方法以序列化Map, 修改KryoPoolSerializer、JdkSerializationSerializer、JacksonJsonSerializer, 实现serializeObj 修改TransactionSerializer的serialize方法,返回时调用serializer.serializeObj(map) 以解决序列化类型转换报错 修改tcc-transaction源码tcc-transaction-spring 增加ScheduleConfiguration、TccTransactionAutoConfiguration 以及资源文件spring.factories 以实现自动配置 3. 在sql/下创建相关表,增加eureka-server、tcc-entity、tcc-repository基础类库 创建tcc-provider-user,配置环境参数, 配置@Compensable,测试单服务confirm和cancel方法执行情况 4. 创建tcc-provider-usercoupon,配置环境参数,增加事务控制,注意Compensable配置propagation = Propagation.SUPPORTS 增加FeignClientService,接收TransactionContext,通过http传递给远程服务, 远程服务根据TransactionStatus分别调用confirmMethod和cancelMethod 5. 测试 #### 使用说明 1. Fork 本仓库 新建 Feat_xxx 分支 git clone 分支 or git clone https://gitee.com/distransaction/tcc-springcloud.git 2. 创建数据库表 执行sql/*.sql,使用dll下的jar包 maven tcc-springcloud(root) clean package 启动eureka-server java -jar eureka-server-0.0.1.jar --spring.profiles.active=server1 java -jar eureka-server-0.0.1.jar --spring.profiles.active=server2 查看注册节点 http://eurekaserver1:8761/ 启动tcc-provider-usercoupon 启动tcc-provider-user 造数据 用户id对应金额为1万元 http://localhost:8801/user/update?userId=1&userMoney=10000 3. 业务测试 测试正常业务,系统内部随机人为制造异常,进行事务回滚 http://localhost:8801/user/testDTrans #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)