【发布时间】:2019-07-11 16:53:04
【问题描述】:
我有三个不同的 Spring boot 项目,它们具有独立的数据库,例如 account-rest、payment-rest、gateway-rest。
- account-rest : 创建一个新帐户
- payment-rest : 创建一个新的付款
- gateway-rest : 调用其他端点
在 gateway-rest 有一个端点调用其他两个端点。
@GetMapping("/gateway-api")
@org.springframework.transaction.annotation.Transactional(rollbackFor = RuntimeException.class)
public String getApi()
{
String accountId = restTemplate.getForObject("http://localhost:8686/account", String.class);
restTemplate.getForObject("http://localhost:8585/payment?accid="+accountId, String.class);
throw new RuntimeException("rollback everything");
}
当我在网关或任何其他端点抛出异常时,我想回滚事务并还原所有内容。
我该怎么做?
【问题讨论】:
标签: spring spring-boot microservices