Comments (3)
https://www.cnblogs.com/savorboard/p/distributed-system-transaction-consistency.html
https://www.cnblogs.com/savorboard/p/cap-auto-transaction.html
from cap.
@yang-xiaodong 感谢大佬回复, 是不是可以这么理解:就是这里的事务只是保 当前数据和消息队列数据持久化的事务,并不是不同微服务之间的事务?
不同微服务之间的数据一致性还是需要通过文中提到的补偿机制来维护?
from cap.
在微服务架构中,由于服务间是松耦合的,保证跨服务的事务数据一致性是一个挑战。发件箱模式(Outbox Pattern)是一种解决这一问题的设计模式,它主要用于处理分布式事务,确保数据的最终一致性,而不是强一致性。这种模式特别适用于那些需要在不同微服务之间进行事件驱动通信的场景。
发件箱模式的工作流程
-
本地事务写入:当一个服务需要执行操作(例如,更新数据库中的数据)并通知其他服务时,它首先在本地数据库中更新业务数据。同时,它还会在同一数据库事务中向一个特殊的“发件箱”表中插入一条记录,这条记录包含了需要传达给其他服务的事件或消息的内容。
-
事件发布:更新和事件插入操作在同一个数据库事务中完成,这保证了数据的一致性。事务提交后,一个独立的发布者(可以是一个轮询机制、数据库触发器或者日志扫描进程)定期扫描发件箱表,捕获新的事件记录。
-
事件传播:发布者读取发件箱中的事件,并将其发布到事件总线或消息队列(如Kafka, RabbitMQ等)上。其他微服务订阅这些事件或消息,根据需要进行处理,实现跨服务的业务逻辑。
-
确认与清理:一旦事件被成功发布到事件总线,相应的发件箱表中的记录可以被标记为已处理或直接删除,以避免重复发送相同的事件。
发件箱模式的优点
- 数据一致性:通过在同一个数据库事务中同时更新业务数据和插入发件箱事件,确保了业务操作和事件通知的一致性。
- 解耦合:服务间通过事件(而非直接调用)进行通信,降低了服务间的耦合度。
- 可靠性:如果事件发布失败,可以重新尝试,直到成功为止,增强了系统的容错能力。
- 顺序保证:通过适当的设计,可以保证事件的顺序性,尤其是对于单一源服务的事件。
发件箱模式是一种有效的策略,用于在保持微服务架构的灵活性和可扩展性的同时,解决跨服务事务数据一致性的问题。正确实施时,它可以大大增强分布式系统的可靠性和维护性。
from cap.
Related Issues (20)
- Question about parallel execution HOT 6
- Error in Nats transport HOT 4
- 能不能加个配置,可以单独启用消费功能或发送功能 ? HOT 2
- How to Introduce Multiple Database Providers? HOT 1
- .NET Core 8 使用RabbitMQ 报No ip address could be resolved for【hostName】的问题 HOT 1
- Optimizing RabbitMQ Performance and Managing Multiple Instances in CAP HOT 2
- Feature Request: Per-Queue Configuration for BasicQos and ConsumerThreadCount HOT 3
- 消息持久化支持达梦数据库吗 HOT 1
- Is the message data structure compatible with older versions of 3.0? HOT 1
- Add new option for parallel publish send. HOT 2
- Add option for controlling reponse headers from OnSubscribeExecuted HOT 2
- NATS Connection Error after Restarting nats-server: Unable to Publish Messages HOT 5
- SQL Server replication readpast error! "You can only specify the READPAST lock in the READ COMMITTED or REPEATABLE READ isolation levels" HOT 3
- 一个进程内可以创建多个CAP吗? HOT 1
- NATS feature: add the possibility to disable dynamic consumer subject/topic creation through NatsCapOtpions HOT 1
- 一个程序进程会操作多个不同的业务数据库,参考#998创建多个发布者进行对应处理,消费者应该如何处理消息? HOT 1
- Feature Request: Add New Column in table Cap.published for relation to table every single data publish HOT 2
- Callback on IIS Idle state HOT 2
- Cap-dashboard empty using dynamic subscribers with Azure Service Bus
- Feature Request:Subscribers can batch process messages HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cap.