feign分布式事务

https://blog.csdn.net/jingYang07/article/details/100122897?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

 

基于redis的一种补偿型处理方案

一、处理TM框架

1、创建springboot项目

2、maven加入

 
  1. <dependency>

  2. <groupId>com.codingapi.txlcn</groupId>

  3. <artifactId>txlcn-tm</artifactId>

  4. <version>5.0.2.RELEASE</version>

  5. </dependency>

3、在启动类加入注解

 

 

3。修改配置文件

 
  1. server:

  2. port: 7970

  3. spring:

  4. application:

  5. name: tx-manager

  6. datasource:

  7. driver-class-name: com.mysql.jdbc.Driver

  8. url: jdbc:mysql://localhost:3306/tx-manager?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

  9. username:

  10. password:

  11. jpa:

  12. database-platform: org.hibernate.dialect.MySQL5InnoDBDialect

  13. hibernate.ddl-auto: update

  14.  
  15. redis:

  16. host: localhost

  17. port: 6379

  18. password:

  19.  
  20. mybatis:

  21. configuration:

  22. map-underscore-to-camel-case: true

  23. use-generated-keys: true

4、在MySQL数据库,新建一个, 名称为: tx-manager库

创建数据表

 
  1. CREATE TABLE `t_tx_exception` (

  2. `id` bigint(20) NOT NULL AUTO_INCREMENT,

  3. `group_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,

  4. `unit_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,

  5. `mod_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,

  6. `transaction_state` tinyint(4) NULL DEFAULT NULL,

  7. `registrar` tinyint(4) NULL DEFAULT NULL,

  8. `remark` varchar(4096) NULL DEFAULT NULL,

  9. `ex_state` tinyint(4) NULL DEFAULT NULL COMMENT '0 未解决 1已解决',

  10. `create_time` datetime(0) NULL DEFAULT NULL,

  11. PRIMARY KEY (`id`) USING BTREE

  12. ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

5、启动TM项目

二、调用项目

1、加入pom.xml

 
  1. <!--分布式锁-->

  2. <dependency>

  3. <groupId>com.codingapi.txlcn</groupId>

  4. <artifactId>txlcn-tc</artifactId>

  5. <version>5.0.2.RELEASE</version>

  6. </dependency>

  7.  
  8. <dependency>

  9. <groupId>com.codingapi.txlcn</groupId>

  10. <artifactId>txlcn-txmsg-netty</artifactId>

  11. <version>5.0.2.RELEASE</version>

  12. </dependency>

2、启动类 加入@EnableDistributedTransaction。

3、调用方法加上注解@LcnTransaction

 

三、被调用项目

1、pom.xml加入

 
  1. <!--分布式锁-->

  2. <dependency>

  3. <groupId>com.codingapi.txlcn</groupId>

  4. <artifactId>txlcn-tc</artifactId>

  5. <version>5.0.2.RELEASE</version>

  6. <scope>compile</scope>

  7. </dependency>

  8. <dependency>

  9. <groupId>com.codingapi.txlcn</groupId>

  10. <artifactId>txlcn-txmsg-netty</artifactId>

  11. <version>5.0.2.RELEASE</version>

  12. </dependency>

2、启动类 加入@EnableDistributedTransaction。

3、被调用方法加上注解@TxcTransaction(propagation = DTXPropagation.REQUIRED)

 

5、启动两个项目 搞定。

 

 

参考文档:https://www.txlcn.org/zh-cn/docs/demo/springcloud.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值