笔记-使用LCN分布式事物demo

注意事项:

1.tx-lcn版本5.0.2.RELEASE,对应springboot版本:2.1.2.RELEASE

2.先启动LCN事务协调器,具体见:【配置LCN事物协调器

3.客户端添加依赖:

<dependency>
	<groupId>com.codingapi.txlcn</groupId>
	<artifactId>txlcn-tc</artifactId>
	<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
	<groupId>com.codingapi.txlcn</groupId>
	<artifactId>txlcn-txmsg-netty</artifactId>
	<version>5.0.2.RELEASE</version>
</dependency>

4.配置事务管理器协调地址

tx-lcn:
  client:
    manager-address: 127.0.0.1:8070

5.添加分布式事务管理器的注解

@SpringBootApplication
@RestController
@EnableDistributedTransaction
public class Service1Application{
    ....
}

6.要进行的所有一串调用的分布式事物都加注解,如果是对数据库操作的话,还需要添加spring事物支持

 @Transactional
    @LcnTransaction
    public void saveUser(String userName) {...}

7.具体代码demo:代码demo

8.查看UI及测试

笔记-使用LCN分布式事物demo

笔记-使用LCN分布式事物demo

9.http://localhost/save?goodsName=apple&userName=李四。第三次的时候事物回滚成功