75 lines
3.9 KiB
Plaintext
75 lines
3.9 KiB
Plaintext
emqx_modules_schema {
|
||
|
||
rewrite {
|
||
desc {
|
||
en: """The topic rewriting function of EMQX supports rewriting topic A to topic B when the client subscribes to topics, publishes messages, and cancels subscriptions according to user-configured rules.
|
||
Each rewrite rule consists of three parts: subject filter, regular expression, and target expression.
|
||
Under the premise that the subject rewriting function is enabled, when EMQX receives a subject-based MQTT message such as a PUBLISH message,
|
||
it will use the subject of the message to sequentially match the subject filter part of the rule in the configuration file. If the match is successful,
|
||
the regular expression is used to extract the information in the subject, and then replaced with the target expression to form a new subject.
|
||
Variables in the format of $N can be used in the target expression to match the elements extracted from the regular expression.
|
||
The value of $N is the Nth element extracted from the regular expression. For example, $1 is the regular expression. The first element extracted by the expression.
|
||
It should be noted that EMQX uses reverse order to read the rewrite rules in the configuration file.
|
||
When a topic can match the topic filter of multiple topic rewrite rules at the same time, EMQX will only use the first rule it matches. Rewrite.
|
||
If the regular expression in this rule does not match the subject of the MQTT message, the rewriting will fail, and no other rules will be attempted for rewriting.
|
||
Therefore, users need to carefully design MQTT message topics and topic rewriting rules when using them."""
|
||
zh: """EMQX 的主题重写功能支持根据用户配置的规则在客户端订阅主题、发布消息、取消订阅的时候将 A 主题重写为 B 主题。
|
||
重写规则分为 Pub 规则和 Sub 规则,Pub 规则匹配 PUSHLISH 报文携带的主题,Sub 规则匹配 SUBSCRIBE、UNSUBSCRIBE 报文携带的主题。
|
||
每条重写规则都由主题过滤器、正则表达式、目标表达式三部分组成。
|
||
在主题重写功能开启的前提下,EMQX 在收到诸如 PUBLISH 报文等带有主题的 MQTT 报文时,将使用报文中的主题去依次匹配配置文件中规则的主题过滤器部分,一旦成功匹配,则使用正则表达式提取主题中的信息,然后替换至目标表达式以构成新的主题。
|
||
目标表达式中可以使用 $N 这种格式的变量匹配正则表达中提取出来的元素,$N 的值为正则表达式中提取出来的第 N 个元素,比如 $1 即为正则表达式提取的第一个元素。
|
||
需要注意的是,EMQX 使用倒序读取配置文件中的重写规则,当一条主题可以同时匹配多条主题重写规则的主题过滤器时,EMQX 仅会使用它匹配到的第一条规则进行重写,如果该条规则中的正则表达式与 MQTT 报文主题不匹配,则重写失败,不会再尝试使用其他的规则进行重写。
|
||
因此用户在使用时需要谨慎的设计 MQTT 报文主题以及主题重写规则。"""
|
||
}
|
||
label {
|
||
en: """Topic Rewrite"""
|
||
zh: """主题重写"""
|
||
}
|
||
}
|
||
|
||
tr_source_topic {
|
||
desc {
|
||
en: """Source topic, specified by the client."""
|
||
zh: """源主题,客户端业务指定的主题"""
|
||
}
|
||
label {
|
||
en: """Source Topic"""
|
||
zh: """源主题"""
|
||
}
|
||
}
|
||
|
||
tr_action {
|
||
desc {
|
||
en: """subscribe: Rewrite topic when client do subscribe.
|
||
publish: Rewrite topic when client do publish.
|
||
all: Both"""
|
||
zh: """subscribe:订阅时重写主题;
|
||
publish:发布时重写主题;
|
||
all:全部重写主题"""
|
||
}
|
||
label {
|
||
en: """Action"""
|
||
zh: """Action"""
|
||
}
|
||
}
|
||
|
||
tr_re {
|
||
desc {
|
||
en: """Regular expressions"""
|
||
zh: """正则表达式"""
|
||
}
|
||
}
|
||
|
||
tr_dest_topic {
|
||
desc {
|
||
en: """Destination topic."""
|
||
zh: """目标主题。"""
|
||
}
|
||
label {
|
||
en: """Destination Topic"""
|
||
zh: """目标主题"""
|
||
}
|
||
}
|
||
|
||
}
|