条件路由规则将符合特定条件的请求转发到特定的地址实例子集上。规则首先对发起流量的请求参数进行匹配,符合匹配条件的请求将被转发到包含特定实例地址列表的子集。
以下是一个条件路由规则示例。
基于以下示例规则,所有 org.apache.dubbo.samples.CommentService
服务 getComment
方法的调用都将被转发到有 region=Hangzhou
标记的地址子集。
configVersion: v3.0 scope: service force: true runtime: true enabled: true key: org.apache.dubbo.samples.CommentService conditions: - method=getComment => region=Hangzhou
条件路由规则主体。定义路由规则生效的目标服务或应用、流量过滤条件以及一些特定场景下的行为。
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 |
Condition
为条件路由规则的主体,类型为一个复合结构的 string 字符串,如 method=getComment => region=Hangzhou
。其中,
匹配条件指定的参数
将与 消费者的请求上下文 (URL)、甚至方法参数
进行对比,当消费者满足匹配条件时,对该消费者执行后面的地址子集过滤规则。过滤条件指定的参数
将与 提供者实例地址 (URL)
进行对比,消费者最终只能拿到符合过滤条件的实例列表,从而确保流量只会发送到符合条件的地址子集。=> status != staging
application = product =>
参数支持
条件支持
值支持