当前位置:网站首页>使用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
边栏推荐
- Google browser realizes video playback acceleration function
- Logo design company, Nanjing
- About Devops seven misunderstandings, 99% of people have been hit!
- 频收罚单的浦发银行:增收不增利,曾遭骗贷数亿元,内控缺位?
- Common mathematical basic formulas of recursive and backtracking algorithms
- 如何使用甘特图图层和筛选器
- 20个XR项目路演,近20个资本机构出席!诚邀您参加2020 Qualcomm XR生态合作伙伴大会
- #JVM 类加载机制
- Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey
- How to solve the problem of blank page in Google Chrome browser
猜你喜欢
August 14, 2020: what are the execution engines for data tasks?
VARCHART XGantt如何在日历上表示工作日
Ora-02292: complete constraint violation (midbjdev2.sys_ C0020757) - subrecord found
2020年新规,微信封号怎么快速解除?
LEADTOOLS如何检测,读取和写入条形码
A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
cubemx做stm32 USB开发
谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
September 3, 2020: naked writing algorithm: loop matrix traversal.
2020-08-15: under what circumstances should data tasks be optimized?
随机推荐
大佬们如何在nginx镜像里面增加模块?
“非洲用户的付费意愿并不低”——专访四达时代研发总监张亮
三步轻松理解Kerberos协议
10000! Ideal car recalls all defective cars: 97 accidents have occurred and losses will be expanded
图像处理工具包ImagXpress使用教程,如何查看事件
Method of code refactoring -- Analysis of method refactoring
关于DevOps的七大误解,99%的人都曾中过招!
南京标志设计,logo设计公司
Cloudquery v1.2.0 release
Gantt chart grouping activities tutorial
Characteristics of magnetic memory chip STT-MRAM
RFID fixed assets management system for fire equipment
Jenkins installation and deployment process
如何才能快速正确的部署甘特图
Windows 10 蓝牙管理页面'添加蓝牙或其他设备'选项点击无响应的解决方案
2020-09-04: do you understand the function call convention?
Google browser realizes video playback acceleration function
The essence of transaction and the principle of deadlock
Do you really know how to use search engines?
#JVM 类加载机制