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
.
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.
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. - If scope:service is set, then key should be specified as the Dubbo service key that this rule targets to control.- 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 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 |
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:
=>
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.=>
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.=> status != staging
application = product =>
Parameter Support
Condition Support
Value Support