如何在两个微服务之间进行两阶段提交(春季启动)? [英] How to do 2 phase commit between two micro-services(Spring-boot)?

查看:318
本文介绍了如何在两个微服务之间进行两阶段提交(春季启动)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个微型服务器A和B连接到单独的数据库,从微型服务器A我需要以相同的转换方式持久保存(保存)A和B的对象.

I Have two mico-serives A and B where they connect to seperate database, From Mico-serives A i need to persist(save) objects of both A and B in same transtation how to achive this.

我正在使用带有netflix-oss的Spring微服务.请提供有关实现两阶段提交的最佳方法的建议.

I am using Spring micro-servies with netflix-oss.Please give suggestions on best way to do achive 2 phase commit.

推荐答案

您不能在分布式环境中的微服务中实现传统的交易系统.

you can not implement traditional transaction system in micro-services in a distributed environment.

您应该使用 Event Sourcing + CQRS 技术,由于它们是原子性的,因此您将获得诸如在整体系统中实现事务或2PC的功能.

You should you Event Sourcing + CQRS technique and because they are atomic you will gain something like implementing transactions or 2PC in a monolithic system.

其他可能的方法是 transaction-log-mining ,我认为链接连接正在使用这种方法,但是它有其优点和缺点.例如不同数据库的二进制日志不同,并且同一数据库中的事件在不同版本之间也有所不同.

Other possible way is transaction-log-mining that I think linked-in is using this way but it has its own cons and pros. for e.g. binary log of different databases are different and event in same kind of database there are differences between different versions.

我建议您在事件存储中使用事件源+ CQRS和字符串事件,然后在微型计算机之间转移多个事件后,根据 CAP定理尝试达到最终一致性.服务A和B,并在每个步骤中更新域状态.

I suggest that you use Event Sourcing + CQRS and string events in an event-store then try reaching eventual consistency base on CAP theorem after transferring multiple events between micro-service A and B and updating domain states in each step.

建议您使用消息代理(例如 ActiveMQ RabbitMQ Kafka )在不同的微服务和字符串之间发送事件源事件它们放在mysql或其他系统等事件存储区中.

It is suggested that you use a message broker like ActiveMQ, RabbitMQ or Kafka for sending event-sourced events between different microservices and string them in an event store like mysql or other systems.

除了模仿交易外,这种方式的另一个好处是您将拥有完整的审核日志.

Another benefit of this way beside mimicking transactions is that you will have a complete audit log.

这篇关于如何在两个微服务之间进行两阶段提交(春季启动)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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