-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
created: 20230719031132183 | ||
modified: 20230719032442286 | ||
title: Tag 标签过滤 | ||
type: text/vnd.tiddlywiki | ||
|
||
# 功能介绍 | ||
|
||
|
||
Tag 标签过滤方式是 RocketMQ 提供的基础消息过滤能力,基于生产者为消息设置的 Tag 标签进行匹配。生产者在发送消息时,设置消息的 Tag 标签,消费者按需指定已有的 Tag 标签来进行匹配订阅。 | ||
过滤语法 | ||
|
||
1. 单 Tag 匹配:过滤表达式为目标 Tag,表示只有消息标签为指定目标 Tag 的消息符合匹配条件,会被发送给消费者; | ||
|
||
2. 多 Tag 匹配:多个 Tag 之间为或的关系,不同 Tag 间使用两个竖线(||)隔开。例如,Tag1||Tag2||Tag3,表示标签为 Tag1 或 Tag2 或 Tag3 的消息都满足匹配条件,都会被发送给消费者进行消费; | ||
|
||
3. 全 Tag 匹配:使用星号(*)作为全匹配表达式。表示主题下的所有消息都将被发送给消费者进行消费。 | ||
|
||
# 技术原理 | ||
|
||
[img[tag过滤原理.png]] | ||
|
||
整个 Tag 标签过滤的流程如下: | ||
|
||
1. 生产者对消息打上自己的业务标签,发送给我们的服务端 Broker; | ||
|
||
2. Broker 将消息写入 CommitLog 中,然后通过异步线程将消息分发到 ConsumeQueue 索引文件中; | ||
|
||
3. 消费者启动后,定时向 Broker 发送心跳请求,将订阅关系上传到 Broker 端,Broker 将订阅关系及标签的哈希值保存在内存中; | ||
|
||
4. 消费者向 Broker 拉取消息,Broker 会通过订阅关系和队列去 ConsumeQueue 中检索消息,将订阅关系中的标签哈希值和消息中的标签哈希值做比较,如果匹配就返回给消费者; | ||
|
||
5. 消费者收到消息后,会将消息中的标签值和本地订阅关系中标签值做精确匹配,匹配成功才会交给消费线程进行消费。 | ||
|
||
<<< | ||
RocketMQ 在存储消息的时候,是通过 Append-Only 的方式将所有主题的消息都写在同一个 CommitLog 文件中,这可以有效的提升了消息的写入速率。为了消费时能够快速检索消息,它会在后台启动异步方式将消息所在位点、消息的大小,以及消息的标签哈希值存储到 ConsumeQueue 索引文件中。将标签存储到这个索引文件中,就是为了在通过标签进行消息过滤的时候,可以在索引层面就可以获取到消息的标签,不需要从 CommitLog 文件中读取,这样就减少消息读取产生的系统 IO 和内存开销。标签存储哈希值,主要是为了保证 ConsumeQueue 索引文件能够定长处理,这样可以有效较少存储空间,提升这个索引文件的读取效率。 | ||
<<< |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
title: tag过滤原理.png | ||
type: image/png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
created: 20230719030148771 | ||
modified: 20230719030257083 | ||
title: 多类型消息传输 | ||
type: text/vnd.tiddlywiki | ||
|
||
* 普通消息 | ||
|
||
* 定时/延时消息 | ||
|
||
* 顺序消息 | ||
|
||
* 事务消息 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
created: 20230719030008802 | ||
modified: 20230719030320828 | ||
tags: 消息队列 | ||
title: 消息系统的四个核心诉求 | ||
type: text/vnd.tiddlywiki | ||
|
||
1)[[多类型消息传输]]:支持多样业务场景集成诉求,主要包括普通消息、定时消息、事务消息、顺序消息等; | ||
|
||
2)丰富[[路由分发能力]]:支持多种分发路由条件,包括 Tag 过滤、消息属性过滤,一对多、一对一分发等; | ||
|
||
3)多样交互模式:支持收发消息多样交互方式,支持同步、异步发送,支持主动消费、被动推送消费,支持流式应答、单条应答; | ||
|
||
4)可观测体系:支持 Metrics、Trace、Events 分析,支持单链路、全链路轨迹追踪,支持 Metrics 分析和监控告警,支持系统运行事件、业务事件透出处理。 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
title: 消息过滤.png | ||
type: image/png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
created: 20230719030436907 | ||
modified: 20230719030503173 | ||
tags: 消息队列 | ||
title: 消息过滤 | ||
type: text/vnd.tiddlywiki | ||
|
||
在消息中间件的使用过程中,一个主题对应的消费者想要通过规则只消费这个主题下具备某些特征的消息,过滤掉自己不关心的消息,这个功能就叫消息过滤。 | ||
|
||
[img[消息过滤.png]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
created: 20230719030346950 | ||
modified: 20230719031119431 | ||
tags: 消息队列 | ||
title: 路由分发能力 | ||
type: text/vnd.tiddlywiki | ||
|
||
# RocketMQ 多样消费功能-消息过滤 | ||
|
||
{{ 消息过滤 }} | ||
|
||
在功能层面,RocketMQ 支持两种过滤方式,[[Tag 标签过滤]]和 [[SQL 属性过滤]]。 |