当前位置:网站首页>消息队列与快递柜之间妙不可言的关系
消息队列与快递柜之间妙不可言的关系
2022-07-07 21:49:00 【InfoQ】
一、消息队列是一个快递柜
- 消息队列比作快递柜:有很多厂家生产快递柜,如:丰巢(apache kafka),速递易(alibaba RocketMQ),近邻宝(ActiveMQ)等等,反正常用的就这几个。快递柜负责临时保存邮件,消息队列负责临时保存消息数据。
- 快递员比作消息生产者:快递员负责向快递柜投递邮件,生产者负责向消息队列投递消息。异曲同工之妙啊!
- 消费者比作消息消费者: 可能是这个例子太贴切了,以至于这句怎么看都是废话。废话也还是要说,生活中的消费者取邮件,程序中的消费者取消息数据。

二、快递柜(消息队列)带来的好处
- 异步解耦:有了快递柜,消费者不用等待快递员,用户体验增强。消费者与生产者(快递员)之间解耦,不会因为对方的操作行为,影响自己独立处事的程序。用户不用疲于等待与接收事件阻塞耗时。
- 流量削峰:我们假定一种极端的情况,你通过各个渠道买了1000本书,突然某一小时集中的给你打电话。你肯定不具备一个小时收1000个邮件的能力,所以你让快递员将邮件放入快递柜。所以你就可以按照自己的处理能力,按照自己的时间安排去取邮件。同样我们的消费者程序在面临多用户、高并发的请求情况下,将数据放入消息队列保存可以将流量数据削峰,按照程序能够处理的能力和资源进行数据消费。
- 缓冲批处理:生产者批量投递,爽!消费者一次性取多个邮件,爽!
三、引入快递柜带来的缺点
- 引入复杂度。毫无疑问,快递柜(消息队列)这东西是多出来的,在原来的收取过程中是不存在的。所以需要地方放它,还需要防火、防盗防潮,需要去维护它。消息队列中间件也是一样的,你需要服务器区安装它,还要对它进行维护。
- 会导致暂时的数据不一致。 如果没有快递柜,你收到了邮件件就是真的收到了。但是使用快递柜之后,你收到了"邮件放入快递柜的消息",但是与你真的取到邮件这中间会有一定的延时。当然你最终还是会取到邮件,选择"消息队列"快递柜,就是要忍受暂时不一致,接受"最终一致性"。
- 当然极端情况下,快递柜坏了,你要不可避免地接受"邮件可能会丢失"的事实,对于安保系数高的小区这几乎不会发生。
边栏推荐
- Line measurement - graphic reasoning -9- line problem class
- Matplotlib quick start
- 安踏DTC | 安踏转型,构建不只有FILA的增长飞轮
- Revit secondary development - wall opening
- Microbial Health Network, How to restore Microbial Communities
- C # realizes the communication between Modbus protocol and PLC
- Leetcode19. Delete the penultimate node of the linked list [double pointer]
- Line test - graphic reasoning - 2 - black and white lattice class
- Personal statement of testers from Shuangfei large factory: is education important for testers?
- 肠道里的微生物和皮肤上的一样吗?
猜你喜欢

Line test - graphic reasoning -7- different graphic classes

Sword finger offer 27 Image of binary tree

How pyGame rotates pictures

Form组件常用校验规则-2(持续更新中~)

Two minutes, talk about some wrong understandings of MySQL index

Robot autonomous exploration DSVP: code parsing

Microbial Health Network, How to restore Microbial Communities
![Leetcode19. Delete the penultimate node of the linked list [double pointer]](/img/a9/809b93d1ffd11ba4a9074ac8e2bdee.jpg)
Leetcode19. Delete the penultimate node of the linked list [double pointer]

Why is network i/o blocked?

0-5vac to 4-20mA AC current isolated transmitter / conversion module
随机推荐
线上面试,该如何更好的表现自己?这样做,提高50%通过率~
Explain in detail the communication mode between arm A7 and risc-v e907 on Quanzhi v853
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
开发那些事儿:Go加C.free释放内存,编译报错是什么原因?
ADC采样率(HZ)是什么怎么计算
Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
How pyGame rotates pictures
Revit secondary development - get the project file path
Visual design form QT designer design gui single form program
Unity technical notes (I) inspector extension
软件测评中心▏自动化测试有哪些基本流程和注意事项?
今日创见|企业促进创新的5大关键要素
“拧巴”的早教行业:万亿市场,难出巨头
Gazebo import the mapping model created by blender
Understand the session, cookie and token at one time, and the interview questions are all finalized
Debezium系列之:支持 mysql8 的 set role 语句
Amesim2016 and matlab2017b joint simulation environment construction
微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
7-51 combination of two ordered linked list sequences
CTF练习