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

二、快递柜(消息队列)带来的好处
- 异步解耦:有了快递柜,消费者不用等待快递员,用户体验增强。消费者与生产者(快递员)之间解耦,不会因为对方的操作行为,影响自己独立处事的程序。用户不用疲于等待与接收事件阻塞耗时。
- 流量削峰:我们假定一种极端的情况,你通过各个渠道买了1000本书,突然某一小时集中的给你打电话。你肯定不具备一个小时收1000个邮件的能力,所以你让快递员将邮件放入快递柜。所以你就可以按照自己的处理能力,按照自己的时间安排去取邮件。同样我们的消费者程序在面临多用户、高并发的请求情况下,将数据放入消息队列保存可以将流量数据削峰,按照程序能够处理的能力和资源进行数据消费。
- 缓冲批处理:生产者批量投递,爽!消费者一次性取多个邮件,爽!
三、引入快递柜带来的缺点
- 引入复杂度。毫无疑问,快递柜(消息队列)这东西是多出来的,在原来的收取过程中是不存在的。所以需要地方放它,还需要防火、防盗防潮,需要去维护它。消息队列中间件也是一样的,你需要服务器区安装它,还要对它进行维护。
- 会导致暂时的数据不一致。 如果没有快递柜,你收到了邮件件就是真的收到了。但是使用快递柜之后,你收到了"邮件放入快递柜的消息",但是与你真的取到邮件这中间会有一定的延时。当然你最终还是会取到邮件,选择"消息队列"快递柜,就是要忍受暂时不一致,接受"最终一致性"。
- 当然极端情况下,快递柜坏了,你要不可避免地接受"邮件可能会丢失"的事实,对于安保系数高的小区这几乎不会发生。
边栏推荐
- Unity and webgl love each other
- Debezium系列之: 支持在 KILL 命令中使用变量
- 行测-图形推理-4-字母类
- [problem] pytorch installation
- Take full control! Create a "leading cockpit" for smart city construction
- What is ADC sampling rate (Hz) and how to calculate it
- ADC采样率(HZ)是什么怎么计算
- 不夸张地说,这是我见过最通俗易懂的,pytest入门基础教程
- The PHP source code of the new website + remove authorization / support burning goose instead of pumping
- Cataloger integrates lidar and IMU for 2D mapping
猜你喜欢

GBU1510-ASEMI电源专用15A整流桥GBU1510

There is another problem just online... Warm

微生物健康网,如何恢复微生物群落

面试百问:如何测试App性能?

行测-图形推理-8-图群类

Micro service remote debug, nocalhost + rainbow micro service development second bullet
![LeetCode206. Reverse linked list [double pointer and recursion]](/img/3c/84351e771ac9763c1e5f7b4921c099.jpg)
LeetCode206. Reverse linked list [double pointer and recursion]

行测-图形推理-5-一笔画类

Line test - graphic reasoning -5- one stroke class

Unity and webgl love each other
随机推荐
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xf9 in position 56: illegal multibyte sequence
Redis集群安装
Revit secondary development - wall opening
Unity development --- the mouse controls the camera to move, rotate and zoom
Sword finger offer 28 Symmetric binary tree
Leetcode94. Middle order traversal of binary trees
Basic knowledge of binary tree
Robot autonomous exploration series papers environment code
双非大厂测试员亲述:对测试员来说,学历重要吗?
行測-圖形推理-4-字母類
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Redis官方ORM框架比RedisTemplate更优雅
Yarn cannot view the historical task log of yarn after enabling ACL user authentication. Solution
Signal feature extraction +lstm to realize gear reducer fault diagnosis -matlab code
Class implementation of linear stack and linear queue (another binary tree pointer version)
Debezium series: support the use of variables in the Kill Command
Revit secondary development - link file collision detection
Debezium系列之:支持 mysql8 的 set role 语句
Install mxnet GPU version
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹