当前位置:网站首页>使用RabbitMQ实现分布式事务
使用RabbitMQ实现分布式事务
2020-11-07 16:49:00 【php开源社区】
RabbitMQ解决分布式事务思路:
案例:经典案例,以目前流行点外卖的案例,用户下单后,调用订单服务,让后订单服务调用派单系统通知送外卖人员送单,这时候订单系统与派单系统采用MQ异步通讯。
RabbitMQ解决分布式事务原理:采用最终一致性原理。
需要保证以下三要素
1、确认生产者一定要将数据投递到MQ服务器中(采用MQ消息确认机制)
2、MQ消费者消息能够正确消费消息,采用手动ACK模式(注意重试幂等性问题)
3、如何保证第一个事务先执行,采用补偿机制,在创建一个补单消费者进行监听,如果订单没有创建成功,进行补单。
如果生产者投递消息到MQ服务器成功
场景1:如果消费者消费消息失败了,生产者是不需要回滚事务的。
解决方案:消费者采用手动ack应答模式,采用MQ进行补偿重试机制,注意MQ补偿幂等性问题。
问题:如何确保生产者投递消息到MQ服务器一定能成功?
解决方案:confirm机制(确认应答机制)。
场景2 如果生产者投递消息到MQ服务器失败,如何解决?
解决方案:使用生产者重试机制进行发消息,注意幂等性问题。
场景3 如何保证一个事务先执行,生产者投递消息到MQ服务器成功,消费者消费成功了,但是订单却回滚了。
解决方案:补单机制。
传统解决方式:
RabbitMq解决方案:
版权声明
本文为[php开源社区]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4479011/blog/4707610
边栏推荐
猜你喜欢
Windows 10 Bluetooth management page 'add Bluetooth or other devices' option click no response solution
How to use Gantt chart layers and filters
Detect certificate expiration script
How to add modules to nginx image?
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
Jenkins installation and deployment process
Insomnia all night
Win7 AppCrash (solution)
How to solve the problem of blank page in Google Chrome browser
汽车维修app开发的好处与功能
随机推荐
2020年新规,微信封号怎么快速解除?
REM: the solution of PC and mobile
The first choice for lightweight GPU applications is the NVIDIA vgpu instance launched by Jingdong Zhilian cloud
JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)
September 3, 2020: naked writing algorithm: loop matrix traversal.
Count the number of project code lines
How to optimize the decoding performance of dynamsoft barcode reader
Getting started with varhart xgantt
Application layer software development Godfather teaches you how to refactor, senior programmers must professional skills
September 9, 2020: naked writing algorithm: two threads print numbers 1-100 in turn.
2020-11-06: go, let's talk about the scheduler.
如何才能快速正确的部署甘特图
Win7 AppCrash (solution)
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
VARCHART XGantt入门教程
大佬们如何在nginx镜像里面增加模块?
如何解决谷歌Chrome浏览器空白页的问题
Using JSON webtoken (JWT) to generate token in nodejs
图像处理工具包ImagXpress使用教程,如何查看事件
August 14, 2020: what are the execution engines for data tasks?