- I have searched the issues of this repository and believe that this is not a duplicate.
Ⅰ. Issue Description
Service A starts a global transaction to call service B. After service B throws an exception, the transaction is not rolled back, and finally seata submits the transaction.
Ⅱ. Describe what happened
service B throws an exception seata submits the transaction.
Ⅲ. Describe what you expected to happen
service A and B rollback
Ⅳ. How to reproduce it (as minimally and precisely as possible)
` @OverRide
服务A
@GlobalTransactional
public ResultVo createOrder(Integer id) {
try {
log.info("当前 XID: {}", RootContext.getXID());
ResultVo resultVo = productFeignSerivce.findById(id);
if (!"200".equals(resultVo.getReturnCode())) {
return ResultVo.fail("查询商品信息失败");
}
Product p = resultVo.getData();
log.info("product:{}", p);
Order order = new Order();
order.setName(p.getName());
order.setPrice(p.getPrice());
orderDao.save(order);
ResultVo desResultVo = productFeignSerivce.desProductCount(p);
if (!"200".equals(desResultVo.getReturnCode())) {
throw new RuntimeException("库存修改失败啦,回滚");
}
if (id.equals(1)){
throw new RuntimeException("手动测试回滚");
}
return ResultVo.success(order);
}catch (Exception e){
throw new RuntimeException(e.getMessage());
}
}
服务B
@OverRide
public int desProductCount(Product product) {
log.info("当前 XID: {}", RootContext.getXID());
if (product == null) {
return 0;
}
// 先执行sql 再异常
int result = productDao.desProductCount(product.getId(), product.getStock() - 1);
// int i = 1 / 0;
return result;
}
`
Ⅴ. Anything else we need to know?
Service A starts the global transaction to call service B. Service A can roll back normally after throwing an exception.
Ⅵ. Environment:
- JDK version : jdk1.8
- OS : windows10
- Others: idea
mybaits+seata
com.alibaba.cloud spring-cloud-starter-alibaba-seata 2.1.1.RELEASE
2条答案
按热度按时间uhry853o1#
@LiPeng960419 do you have used the dependency of
spring-cloud-alibaba-seata
?e4yzc0pl2#
@LiPeng960419 do you have used the dependency of
spring-cloud-alibaba-seata
?spring-cloud-starter-alibaba-seata includes spring-cloud-alibaba-seata