【发布时间】:2020-08-01 19:31:29
【问题描述】:
我正在使用 Spring Boot,但在 Transactions 方面没有太多经验...
@Service
@Transactional
class FundTransferService {
public void doSomeFunds(){
if(realPaymentGateway()){
//then do db call, to update User Transaction details, WHAT IF SERVER GOES DOWN HERE OR ANY EXCEPTION??
}
}
public boolean realPaymentGateway(){
//Using Braintree to transfer Funds
}
}
上面发生了两件事,paymentGateway(这是一些休息电话),如果成功,则只需 使用用户交易详细信息更新数据库。
我希望以上 2 件事应该发生原子,我的意思是(休息和 DB)都成功,或者回滚一切..
我的问题是:
Q1)在更新数据库详细信息时,由于某些异常或服务器出现故障,可能仅针对数据库内容发生回滚,而不是 RESTCALL..
Q2) 我应该先更新数据库,然后再使用 PaymentGateway 进行资金转移还是反向应该是正确的?请给我建议..
希望您能理解我的问题,那么上述问题的解决方案是什么?
【问题讨论】:
-
那么,真的没有办法阻止吗?那么亚马逊、Ebay 或其他电子商务网站等大型网站的表现如何?
标签: spring spring-boot transactions spring-data-jpa spring-transactions