微服务中的事务 [英] Transactions in microservices

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

问题描述

我读过一些关于微服务架构的文章,但没有人涉及事务的话题.他们都说这很难做到.也许有人可以描述如何处理这个问题?

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天全站免登陆