This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git
The following commit(s) were added to refs/heads/master by this push:
new 2fe914296a3 Enhance Condition Routing Rule doc (#2901)
2fe914296a3 is described below
commit 2fe914296a3898c54d208f01bba3ef91142ce6c0
Author: xixingya <[email protected]>
AuthorDate: Thu Jan 11 20:19:08 2024 +0800
Enhance Condition Routing Rule doc (#2901)
* Update condition-rule.md
* fix
* add english
* add english
* add english
---
.../core-features/traffic/condition-rule.md | 72 ++++++++++++++++++++--
.../core-features/traffic/condition-rule.md | 31 ++++++----
2 files changed, 88 insertions(+), 15 deletions(-)
diff --git a/content/en/overview/core-features/traffic/condition-rule.md
b/content/en/overview/core-features/traffic/condition-rule.md
index a2992f52334..4fab76a60d2 100644
--- a/content/en/overview/core-features/traffic/condition-rule.md
+++ b/content/en/overview/core-features/traffic/condition-rule.md
@@ -1,8 +1,72 @@
---
-type: docs
-title: "条件路由规则"
-linkTitle: "条件路由"
-weight: 10
+aliases:
+ - /en/overview/core-features/traffic/condition-rule/
description: ""
+linkTitle: Conditional Routing
+title: Conditional Routing Rules
+type: docs
+weight: 1
---
+
+
+Conditional routing rules forward requests that meet specific conditions to a
subset of destination instances. The rules match the request parameters of
incoming traffic, and requests that meet the matching criteria are forwarded to
a subset that contains a specific list of instance addresses.
+
+Here is an example of a conditional routing rule.
+
+Based on the following example rule, all invocations of the `getComment`
method in the `org.apache.dubbo.samples.CommentService` service will be
forwarded to a subset of addresses marked with `region=Hangzhou`.
+
+ ```yaml
+ configVersion: v3.0
+ scope: service
+ force: true
+ runtime: true
+ enabled: true
+ key: org.apache.dubbo.samples.CommentService
+ conditions:
+ - method=getComment => region=Hangzhou
+ ```
+
+ You can refer to specific example code for conditional routing
[here](https://github.com/apache/dubbo-samples/tree/master/4-governance/dubbo-samples-configconditionrouter/src/main/java/org/apache/dubbo/samples/governance).
+## ConditionRule
+The body of a conditional routing rule defines the target service or
application on which the routing rule will take effect, the traffic filtering
conditions, and the behaviors in certain specific scenarios.
+
+| Field | Type | Description
| Required |
+| --- | ---
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
--- |
+| configVersion | string | The version of the condition rule definition,
currently available version is `v3.0`
| Yes |
+| scope | string | Supports `service` and `application` scope rules.
| Yes |
+| key | string | The identifier of the target service or application that this
rule is about to apply to. <br/><br/>- If `scope:service`is set, then
`key`should be specified as the Dubbo service key that this rule targets to
control.<br/> - If `scope:application` is set, then `key`should be specified as
the name of the application that this rule targets to control, application
should always be a Dubbo Consumer. | Yes |
+| enabled | bool | Whether enable this rule or not, set `enabled:false` to
disable this rule.
| Yes |
+| conditions | string[] | The condition routing rule definition of this
configuration. Check [Condition](./#condition) for details
| Yes |
+| force | bool | The behavior when the instance subset is empty after routing.
`true` means return no provider exception while `false` means ignore this rule.
| No |
+| runtime | bool | Whether run routing rule for every rpc invocation or use
routing cache if available.
| No |
+
+## Condition
+
+The `Condition` serves as the body of a conditional routing rule and is of
type string with a composite structure, such as `method=getComment =>
region=Hangzhou`. Here:
+
+* The conditions before the `=>` symbol indicate the request parameter
matching conditions. The specified `matching conditions` are compared with the
consumer's request context (URL) or even method parameters. When the consumer
satisfies the matching conditions, the address subset filtering rules following
the conditions will be applied to the consumer.
+* The conditions after the `=>` symbol represent the address subset filtering
conditions. The specified `filtering conditions` are compared with the
provider instance addresses (URLs). The consumer can only access instances that
meet the filtering conditions, ensuring that traffic is only sent to the subset
of addresses that meet the conditions.
+ * If the matching conditions are empty, it means the rule applies to all
requests, for example:`=> status != staging`
+ * If the filtering conditions are empty, it denies access from the
corresponding requests, for example: `application = product =>`
+
+### Matching/Filtering Conditions
+
+**Parameter Support**
+* Service invocation context, such as interface, method, group, version, etc.
+* Request context, such as attachments[key] = value.
+* Method parameters, such as arguments[0] = tom.
+* Fields in the URL itself, such as protocol, host, port, etc.
+* Additional parameters on the URL, such as application, organization, etc.
+* Supports developer-defined extensions.
+
+**Condition Support**
+* The equal sign (=) represents "match," for example: method = getComment.
+* The not-equal sign (!=) represents "not match," for example: method !=
getComment.
+
+**Value Support**
+* Multiple values separated by commas (,), for example: host !=
10.20.153.10,10.20.153.11.
+* Ending with an asterisk () denotes wildcard matching, for example: host !=
10.20..
+* Starting with a dollar sign ($) indicates referencing consumer parameters,
for example: region = $region.
+* Integer value ranges, for example: userId = 1~100, userId = 101~.
+* Supports developer-defined extensions.
diff --git a/content/zh-cn/overview/core-features/traffic/condition-rule.md
b/content/zh-cn/overview/core-features/traffic/condition-rule.md
index 5190a386ef7..8fb8e7865d4 100644
--- a/content/zh-cn/overview/core-features/traffic/condition-rule.md
+++ b/content/zh-cn/overview/core-features/traffic/condition-rule.md
@@ -6,6 +6,7 @@ linkTitle: 条件路由
title: 条件路由规则
type: docs
weight: 1
+
---
@@ -26,30 +27,36 @@ weight: 1
conditions:
- method=getComment => region=Hangzhou
```
+
+可以看具体的例子代码:
[条件路由](https://github.com/apache/dubbo-samples/tree/master/4-governance/dubbo-samples-configconditionrouter/src/main/java/org/apache/dubbo/samples/governance)
+
## ConditionRule
+
条件路由规则主体。定义路由规则生效的目标服务或应用、流量过滤条件以及一些特定场景下的行为。
-| Field | Type | Description
| Required |
-| --- | ---
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
--- |
-| configVersion | string | The version of the condition rule definition,
currently available version is `v3.0`
| Yes |
-| scope | string | Supports `service` and `application` scope rules.
| Yes |
-| key | string | The identifier of the target service or application that this
rule is about to apply to. <br/><br/>- If `scope:service`is set, then
`key`should be specified as the Dubbo service key that this rule targets to
control.<br/> - If `scope:application` is set, then `key`should be specified as
the name of the application that this rule targets to control, application
should always be a Dubbo Consumer. | Yes |
-| enabled | bool | Whether enable this rule or not, set `enabled:false` to
disable this rule.
| Yes |
-| conditions | string[] | The condition routing rule definition of this
configuration. Check [Condition](./#condition) for details
| Yes |
-| force | bool | The behavior when the instance subset is empty after routing.
`true` means return no provider exception while `false` means ignore this rule.
| No |
-| runtime | bool | Whether run routing rule for every rpc invocation or use
routing cache if available.
| No |
+| 字段名 | 类型 | **描述**
| 必填 |
+| --- | ---
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
---- |
+| configVersion | string | 条件路由的版本,当前版本为 `v3.0` |
是 |
+| scope | string | 支持 `service` 和 `application` 两种规则
| 是 |
+| key | string | 应用到的目标服务或应用程序的标识符<br/><br/>- 当 `scope:service` 时,
`key`应该是该规则生效的服务名比如 org.apache.dubbo.samples.CommentService<br/> - 当
`scope:application` 时, then `key`应该是该规则应该生效的应用名称,比如说my-dubbo-service. | 是 |
+| enabled | bool | 规则是否生效 当 `enabled:false` 时,规则不生效 |
是 |
+| conditions | string[] |
配置中定义的条件规则,详情可以看[条件规则](https://cn.dubbo.apache.org/zh-cn/overview/core-features/traffic/condition-rule/#condition)
| 是 |
+| force | bool | T路由后实例子集为空时的行为。 `true` 则抛出一个No Provider
Exception。 `false` 则忽略规则,直接去请求其他的实例。默认值是false | 否 |
+| runtime | bool | 是否为每个 rpc
调用运行路由规则或使用路由缓存(如果可用)。默认值是false(false则走缓存,true不走缓存) | 否 |
## Condition
`Condition` 为条件路由规则的主体,类型为一个复合结构的 string 字符串,如 `method=getComment =>
region=Hangzhou`。其中,
+
* => 之前的为请求参数匹配条件,指定的 `匹配条件指定的参数` 将与 `消费者的请求上下文 (URL)、甚至方法参数`
进行对比,当消费者满足匹配条件时,对该消费者执行后面的地址子集过滤规则。
* => 之后的为地址子集过滤条件,指定的 `过滤条件指定的参数` 将与 `提供者实例地址 (URL)`
进行对比,消费者最终只能拿到符合过滤条件的实例列表,从而确保流量只会发送到符合条件的地址子集。
- * 如果匹配条件为空,表示对所有请求生效,如:`=> status != staging`
- * 如果过滤条件为空,表示禁止来自相应请求的访问,如:`application = product =>`
+ * 如果匹配条件为空,表示对所有请求生效,如:`=> status != staging`
+ * 如果过滤条件为空,表示禁止来自相应请求的访问,如:`application = product =>`
### 匹配/过滤条件
**参数支持**
+
* 服务调用上下文,如:interface, method, group, version 等
* 请求上下文,如 attachments[key] = value
* 方法参数,如 arguments[0] = tom
@@ -58,10 +65,12 @@ weight: 1
* 支持开发者自定义扩展
**条件支持**
+
* 等号 = 表示 "匹配",如:method = getComment
* 不等号 != 表示 "不匹配",如:method != getComment
**值支持**
+
* 以逗号 , 分隔多个值,如:host != 10.20.153.10,10.20.153.11
* 以星号 * 结尾,表示通配,如:host != 10.20.*
* 以美元符 $ 开头,表示引用消费者参数,如:region = $region