当前位置:网站首页>MQ教程 | Exchange(交换机)
MQ教程 | Exchange(交换机)
2022-07-02 11:06:00 【不是二师兄的八戒】
Exchange
Producer 将消息发送到 Exchange ,由 Exchange 将消息路由到一个或多个 Queue 中(或者丢弃)。Exchange 根据 Routing Key 和 Binding Key 将消息路由到 Queue。不同类型的 Exchange 的路由规则不同。消息队列 AMQP 版目前支持三种类型的 Exchange:
- Direct Exchange
- Topic Exchange
- Fanout Exchange
Direct Exchange
- 路由模式根据 Binding Key = Routing Key 的规则路由消息。
- 使用场景区分发往同一个 Exchange 的消息。
- 示例图 1. Direct Exchange
Direct Exchange 分别与 Queue A 和 Queue B 绑定。Consumer 可以从 Queue A 中拉取所有图片(img)创建(create)消息,从 Queue B 中拉取所有图片(img)日志(log)消息。
- Direct Exchange 绑定 Queue:
- Direct Exchange 和 Queue A 的 Binding Key 为 img.create。
- Direct Exchange 和 Queue B 的 Binding Key 为 img.log。
- Producer 向 Direct Exchange 发送消息:
- 消息 A 的 Routing Key 为 img.create。
- 消息 B 的 Routing Key 为 img.log。
- Direct Exchange 根据 Binding Key = Routing Key 的规则路由消息:
- Routing Key 为 img.create 的消息 A 路由至 Binding Key 为 img.create 的 Queue A。
- Routing Key 为 img.log 的消息 B 路由至 Binding Key 为 img.log 的 Queue B。
Topic Exchange
- 路由规则根据通配符匹配路由消息。
- 星号(*)代表一个单词(例如:cn)。
- 井号(#)代表零个、一个或多个单词,单词间通过英文句号(.)分隔(例如:cn.zj.hz)。
- 使用场景通过 Topic 对消息进行区分。
- 示例图 2. Topic Exchange
Topic Exchange 分别与 Queue A 和 Queue B 绑定。Consumer 可以从 Queue A 中拉取所有中国(cn)杭州(hz)的文件(files),从 Queue B 中拉取所有中国(cn)商店(store)的文件(files)。
- Topic Exchange 绑定 Queue:
- Topic Exchange 和 Queue A 的 Binding Key 为 files.cn.hz.#。
- Topic Exchange 和 Queue B 的 Binding Key 为 files.cn.*.store。
- Producer 向 Topic Exchange 发送消息:
- 消息 A 的 Routing Key 为 files.cn.hz。
- 消息 B 的 Routing Key 为 files.cn.hz.store。
- 消息 C 的 Routing Key 为 files.cn.sz.store。
- Topic Exchange 根据通配符匹配的规则路由消息:
- Routing Key 为 files.cn.hz 的消息 A 路由至 Binding Key 为 files.cn.hz.# 的 Queue A。
- Routing Key 为 files.cn.hz.store 的消息 B 路由至 Binding Key 为 files.cn.hz.# 的 Queue A 和 Binding Key 为 files.cn.*.store 的 Queue B。
- Routing Key 为 files.cn.sz.store 的消息 C 路由至 Binding Key 为 files.cn.*.store 的Queue B。
Fanout Exchange
- 路由规则Fanout Exchange 无视 Routing Key 和 Binding Key 的匹配规则,将消息投递至所有绑定的 Queue。
- 使用场景广播消息。
- 示例图 3. Fanout Exchange
Fanout Exchange 将消息投递至所有绑定的 Queue,Consumer 可以从所有 Queue 中拉取同一消息。
- Fanout Exchange 绑定 Queue:Fanout Exchange 和 Queue A、Queue B、Queue C 的 Binding Key 都可以为任意值。
- Producer 向 Fanout Exchange 发送消息:消息 A 的 Routing Key 可以为任意值。
- Fanout Exchange 将消息路由至所有绑定的 Queue:Routing Key 为任意值的消息 A 分别路由至 Binding Key 为任意值的 Queue A、Queue B、Queue C。
边栏推荐
- < schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
- selenium 元素定位方法
- HMS core machine learning service helps zaful users to shop conveniently
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- YOLOv3&YOLOv5输出结果说明
- TeamTalk源码分析之win-client
- Use of UIC in QT
- How kaggle uses utility script
- Everyone believes that the one-stop credit platform makes the credit scenario "useful"
- Basic knowledge of QT original code
猜你喜欢
In 2021, the global styrene butadiene styrene (SBS) revenue was about $3722.7 million, and it is expected to reach $5679.6 million in 2028
默认插槽,具名插槽,作用域插槽
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
SystemServer进程
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
BeanUtils -- shallow copy -- example / principle
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
QT new project
每日学习3
Qt入门-制作一个简易的计算器
随机推荐
Default slot, named slot, scope slot
freemarker的使用
Custom events, global event bus, message subscription and publishing, $nexttick
Packet capturing tool Fiddler learning
测试框架TestNG的使用(二):testNG xml的使用
Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
Development skills of rxjs observable custom operator
瀏覽器驅動的下載
Will your sleep service dream of the extra bookinfo on the service network
给Android程序员的一些面试建议「建议收藏」
Qt原代码基本知识
Federated Search: all requirements in search
Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te
P3008 [usaco11jan]roads and planes g (SPFA + SLF optimization)
软件测试的方法
Dingtalk send message
Qt新建项目
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
Use bloc to build a page instance of shutter