[英]How to do 2 phase commit between two micro-services(Spring-boot)?
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. 我有两个mico-serives A和B,它们连接到单独的数据库,从Mico-serives A我需要在同一个转换中持久保存(保存)A和B的对象如何实现这一点。
I am using Spring micro-servies with netflix-oss.Please give suggestions on best way to do achive 2 phase commit. 我正在使用带有netflix-oss的Spring微服务。请给出关于执行2阶段提交的最佳方法的建议。
you can not implement traditional transaction system in micro-services in a distributed environment. 您无法在分布式环境中的微服务中实现传统的事务系统。
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. 您应该使用事件采购+ CQRS技术,因为它们是原子的,您将获得类似于在单片系统中实现事务或2PC的功能。
Other possible way is transaction-log-mining that I think linked-in is using this way but it has its own cons and pros. 其他可能的方式是事务日志挖掘 ,我认为link-in正在使用这种方式,但它有自己的缺点和优点。 for eg binary log of different databases are different and event in same kind of database there are differences between different versions.
例如,不同数据库的二进制日志不同,同一种数据库中的事件在不同版本之间存在差异。
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. 我建议您在事件存储中使用Event Sourcing + CQRS和字符串事件,然后在微服务A和B之间传输多个事件并在每个步骤中更新域状态后尝试达到CAP定理的 最终一致性 。
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. 建议您使用ActiveMQ , RabbitMQ或Kafka等消息代理在不同的微服务之间发送事件源事件,并将它们串在mysql或其他系统等事件存储中。
Another benefit of this way beside mimicking transactions is that you will have a complete audit log . 除了模仿事务之外,这种方式的另一个好处是您将拥有完整的审计日志 。
It is an architecture(microservices) problem. 这是一个架构(微服务)问题。 Spring boot or netflix-oss do not offer a direct solution.
Spring boot或netflix-oss不提供直接解决方案。 You have to implement your own solution.
您必须实施自己的解决方案。 Check with event driven architecture .
检查事件驱动架构 。 It can give you some ideas.
它可以给你一些想法。
您可以尝试使用SAGA模式https://microservices.io/patterns/data/saga.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.