You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "chickenlj (GitHub)" <gi...@apache.org> on 2018/12/07 09:34:57 UTC

[GitHub] [incubator-dubbo] chickenlj opened issue #2914: [2.7.0-development docs] Routing rules

## 路由规则回顾

Dubbo提供了具有一定扩展性的[路由规则](http://dubbo.apache.org/zh-cn/docs/user/demos/routing-rule.html),其中具有代表性的是条件路由和脚本路由。

## 面临的问题

- 路由规则存储在注册中心
- 只支持服务粒度的路由,应用级别无法定义路由规则
- 支持路由缓存,但基本不具有扩展性
- 一个服务或应用允许定义多条路由规则,服务治理无法管控
- 实现上,每条规则生成一个Router实例并动态加载

## 解决方法

### 类图

![router uml](https://user-images.githubusercontent.com/18097545/49639534-38a82b00-fa46-11e8-805b-a8c1a31c155a.jpg)


我们简单概括下各个类的协作关系。

- RegistryDirectory,包含完整的地址列表,直接对接注册中心,并动态接收注册中心地址变更。
- RouterChain,由Router组装成的列表,是路由动作的入口,接收传入的地址列表并将过滤后的地址列表返回给调用方,而具体的过滤动作则委托给Router执行
- Router,接收并解析路由规则,接收地址列表,根据路由规则完成过滤动作,并返回过滤后的地址列表。其本身也是一个ConfigurationListener,随时接收路由规则更新。
- ConfigurationListener,动态配置变更的回调接口
- DynamicConfiguration,动态配置SPI,支持的扩展实现包括Zookeeper、Apollo、Nacos等



### 工作流程或时序图

- refer、地址变更及规则变更

![Router Sequence]
![router sequence](https://user-images.githubusercontent.com/18097545/49639602-5ffef800-fa46-11e8-8d45-b668538f4d94.png)

1. 由ReferenceConfig触发refer流程,RegisryProtocol首先实例化DynamicConfiguration扩展,生成Router链buildRouterChain(自动加载的RouterChainFactory)
2. subscribe向注册中心订阅provider地址列表,注册中心订阅时是一个同步等地址列表的过程,拿到urls后,用DynamicConfiguration中中的规则来做合并,
3. 变更通知。如果地址列表变化,Registry通知;如果路由规则变化,DynamicConfiguration通知
4. RPC请求,Directory中返回routerChain.route过滤后的可用地址



- RPC请求

  【补充时序图】

### conditionRouter

- 主体规则和原路由规则保持一致,转化为route:// ConditionRouter执行
- 增加应用粒度的路由规则配置,既可以对所有服务生效,也可选择对某个服务生效

```yaml
# application level, applies to all services
---
scope: application
force: true
runtime: false
enabled: true
priority: 1
key: demo-consumer
conditions:
  - method!=sayHello => address=30.5.120.16:20880
  - method=routeMethod1 =>
...

# application level, only applies to a specific service
---
scope: application
force: true
runtime: false
enabled: true
priority: 1
key: demo-consumer
conditions:
  - interface=org.apache.dubbo.demo.DemoService&method!=sayHello => host=30.5.120.16
  - interface=org.apache.dubbo.demo.DemoService&method=routeMethod1 => address=30.5.120.16:20880
...

# service level
---
scope: service
force: true
runtime: false
enabled: true
priority: 1
key: org.apache.dubbo.demo.DemoService
conditions:
  - method!=sayHello =>
  - method=routeMethod1 => address=30.5.120.16:20880
...
```

####  

### TagRouter

- Tag的改进版本,支持动态归组的路由规则
- 同时支持静态配置和动态归组,以动态归组为准
- attachments或静态配置指定消费tag
- 以Provider应用粒度指定或变更tag分组:语义合理、性能

```yaml
---
force: true
runtime: false
enabled: true
priority: 1
key: demo-provider
tags:
  - name: tag1
    addresses: [30.5.120.16:20880, 30.5.120.16:20881]
  - name: tag2
    addresses: [30.5.120.16:20881]
...
```

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2914 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] chickenlj closed issue #2914: [2.7.0-development docs] Routing rules

Posted by "chickenlj (GitHub)" <gi...@apache.org>.
[ issue closed by chickenlj ]

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2914 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] kimmking commented on issue #2914: [2.7.0-development docs] Routing rules

Posted by "kimmking (GitHub)" <gi...@apache.org>.
that's great, router is useful feature for mock service and dynamic runtime strategy.

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/2914 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org