说明:本项目springCloud+springboot+gradle
一,tx_manager
1,拷贝一个服务改造成tx_manager,只需要改服务名,本身是一个空项目
2,启动类加注解
@EnableTransactionManagerServer
3,添加tx_manager依赖,和客户端依赖不同
compile 'com.codingapi.txlcn:txlcn-tm:5.0.2.RELEASE'
4,修改配置信息
server: port: 7970 spring: application: name: tx-manager
启动,结果启动失败
二,tx_client
把原来服务作为客户端
1,启动类添加注解
@EnableDistributedTransaction
2,添加依赖
compile 'com.codingapi.txlcn:txlcn-tc:5.0.2.RELEASE' compile 'com.codingapi.txlcn:txlcn-txmsg-netty:5.0.2.RELEASE'
3,修改配置
tx-lcn: client: manager-address: 127:0:0:1:8070
4,事务方法注解,调用方和被调用方添加注解,官网注解有的相同如下,有的不同搞不懂
@LcnTransaction
详细参考官网
感觉官网讲的也不清,尤其是tx_manager的部分
我也在网上搜了很多其他的关于分布式文章,但是大多数不是参考官网
1,tx_manager从官网下载,作为单独服务
2,依赖是这个
/* compile('com.codingapi:transaction-springcloud:4.1.0'){ exclude group: 'org.slf4j', module: '*' } compile('com.codingapi:tx-plugins-db:4.1.0'){ exclude group: 'org.slf4j', module: '*' }*/
3,事务方法上加的注解也不同,是这个
@TxTransaction(isStart = true)
可参考文章:
https://blog.csdn.net/zhangxing52077/article/details/81587988