微服务交易 [英] Transactions in microservices

查看:78
本文介绍了微服务交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些有关微服务体系结构的文章,但是没有人讨论事务的话题.他们说的一切都很难做到.也许有人可以描述如何处理?

I have read some articles about microservices architecture, but no one takes the topic of transaction. All that they says that this is hard to do it. Maybe someone can describe how to handle this?

但不是从领域方面而是从技术方面.假设我们有一个业务案例,其中我们需要调用两个不同的服务,并且这两个服务都需要对数据库进行一些更改.但是,如果第二个错误发生,该如何回滚呢?

But not from domain side, but from technology side. Lets say that we have business case where we need to invoke two different services and both of them make some changes on database. But how to rollback if some error occurs on the second one?

谁知道这个问题的某些库或设计模式?

Who knows some libraries or design patter for this problem?

推荐答案

最好的设计是具有隔离的服务:每个服务仅在其自己的事务中完成其工作,并且您的工作流预计单个服务会失败.

The best design is having isolated services: each service just do its work within its own transaction and your workflow expects failures on the single service.

如果仅在调用所有服务时都没有错误的情况下才真正需要提交,则应创建一个在外部事务中执行这些调用的更高级别的服务.

If you really need to commit only if all the services are called without errors you should create an higher level service that perform those calls inside an external transaction.

这篇关于微服务交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆