Seata版本1.3.0
SpringBoot版本 2.3.0.RELEASE
Seata依赖
`
<artifactId>seata-all</artifactId>
<version>1.7.0</version>
</dependency>
<!--If your project base on `Spring Boot`, you can directly use the following dependencies-->
<!--Notice: `seata-spring-boot-starter` has already included `seata-all` dependency-->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.7.0</version>
</dependency>
<!-- seata序列化 -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-serializer-kryo</artifactId>
<version>1.7.0</version>
</dependency>`
Server1 Seata 配置如下:
seata.client.undo.log-serialization=kryo seata.data-source-proxy-mode=AT seata.application-id=gallop-admin seata.service.grouplist.default=192.168.xx.xx:8091 seata.service.vgroup-mapping.demo-gallop-admin-group=default seata.tx-service-group=demo-gallop-admin-group
Server2 Seata 配置如下:
seata.client.undo.log-serialization=kryo seata.data-source-proxy-mode=AT seata.application-id=gallop-remote seata.service.grouplist.default=192.168.xx.xx:8091 seata.service.vgroup-mappingdemo-gallop-remote-group=default seata.tx-service-group=demo-gallop-remote-group
代码如下:
` @Resource private RemoteCommandClient remoteCommandClient;
@GlobalTransactional(rollbackFor = Exception.class)
@Override
public ResponseResult addOrUpdateUserTest(User user) {
userMapper.insert(user);
ResponseResult result = remoteCommandClient.updateCMDState("f514b2c693d5495384ad5f61191f34f2","我来了");
userMapper.insert(user);
return null;
}
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public ResponseResult updateCMDState(String commandId, String commandResponse) {
RemoteCommandsHistory history = new RemoteCommandsHistory();
history.setCommandId(commandId);
history.setCommandResponse(commandResponse);
history.setCommandResponseTime(LocalDateTime.now());
return remoteCommandsHistoryMapper.updateById(history) == 0 ? ResponseResult.ok(ResponseCode.FAIL,
ResponseMessage.FAIL) : ResponseResult.ok(ResponseCode.SUCCESS, ResponseMessage.SUCCESS);
}
`
运行结果: 运行到第二个userMapper.insert会出现主键冲突异常 此时第一个userMapper.insert回滚 remoteCommandClient.updateCMDState未回滚
seata日志如下:
求大佬指点!!!