简体   繁体   English

如何在两个微服务(Spring-boot)之间进行两阶段提交?

[英]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. 建议您使用ActiveMQRabbitMQKafka等消息代理在不同的微服务之间发送事件源事件,并将它们串在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.

相关问题 Java Spring-boot 微服务异常处理 - Java Spring-boot micro-services Exception handling 如何将Spring-boot调度器设计为Service,以便其他微服务可以使用 - How to Design a Spring-boot scheduler as Service, so that other micro-services can use it 如何在spring-boot中启用跨域微服务 - How to enable cross-origin in spring -boot for micro-services 使用微服务和Spring Boot进行分布式事务 - distributed transactions with micro-services and Spring Boot 用于Spring启动微服务的MySQL配置 - MySQL configuration for Spring boot micro-services 微服务授权和会话维护-Spring Boot - Micro-services Authorization and session maintenance - spring boot 两个微服务之间的双向通信(spring boot) - Two way communication between two micro services (spring boot) Netflix Arcaius充当多个Spring Boot微服务的配置服务 - Netflix Arcaius serving as config service for multiple Spring Boot micro-services 使用Angular和Spring Boot微服务的基于PKI证书的身份验证 - PKI certificate based authentication using Angular and Spring Boot Micro-services Apache Camel 是否替代或补充使用 Spring Boot 创建微服务? - Does Apache Camel replace or complement creating micro-services with Spring Boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM