开篇
为了统一不同配置中心(如Zookeeper、Nacos、Etcd等)对于服务治理规则的实现,Dubbo2.7.3及之后的版本针对2.7.0以来的配置中心的部分实现进行了重构。
从实际代码来看,Dubbo Admin针对应用维度的配置的实际生效需要在Dubbo 2.7.3及以后的版本,为了方便debug建议Dubbo的版本是dubbo-2.7.4.1。
Dubbo Admin新版本的github地址为dubbo-admin。
演示效果
配置中心
配置目录结构
[zk] ls /dubbo/config/dubbo
[dubbo-demo-api-provider.configurators, dubbo-demo-api-consumer.configurators, org.apache.dubbo.demo.DemoService.configurators]
Dubbo 2.7.X的配置中心目录在/dubbo/config/dubbo,不在像Dubbo 2.6.X一样在/dubbo/service/configurators下。
Dubbo 2.7.X的配置中心的命令规则为/dubbo/config/dubbo/applicationName. configName 或 /dubbo/config/dubbo/serviceName.configName
consumer侧的配置
[zk] get /dubbo/config/dubbo/dubbo-demo-api-consumer.configurators
configs:
- addresses:
- ''
enabled: true
parameters:
weight: 111
side: provider
type: weight
enabled: false
key: dubbo-demo-api-consumer
scope: application
[zk] get /dubbo/config/dubbo/dubbo-demo-api-consumer.tag-router
enabled: true
force: false
key: dubbo-demo-api-consumer
priority: 0
runtime: false
tags:
- addresses:
- 192.168.0.1:20881
name: tag1
- addresses:
- 192.168.0.2:20882
name: tag2
provider侧的配置
[zk] get /dubbo/config/dubbo/dubbo-demo-api-provider.configurators
configs:
- addresses:
- ''
enabled: true
parameters:
weight: 10
side: provider
type: weight
- enabled: true
parameters:
loadbalance: leastactive
side: consumer
type: balancing
enabled: false
key: dubbo-demo-api-provider
scope: application
[zk] get /dubbo/config/dubbo/dubbo-demo-api-provider.condition-router
conditions:
- => host != 172.22.3.91
enabled: true
force: true
key: dubbo-demo-api-provider
priority: 0
runtime: false
scope: application
[zk] get /dubbo/config/dubbo/dubbo-demo-api-provider.tag-router
enabled: true
force: false
key: dubbo-demo-api-provider
priority: 0
runtime: false
tags:
- addresses:
- 192.168.0.1:20881
name: tag1
- addresses:
- 192.168.0.2:20882
name: tag2
service纬度的配置
[zk] get /dubbo/config/dubbo/org.apache.dubbo.demo.DemoService.configurators
configs:
- addresses:
- ''
enabled: true
parameters:
weight: 10
side: provider
type: weight
- enabled: true
parameters:
.loadbalance: leastactive
side: consumer
type: balancing
enabled: false
key: org.apache.dubbo.demo.DemoService
scope: service
Dubbo Admin 调试步骤
1、官方git仓库 dubbo-admin下载dubbo-admin的源码。
2、参考官网运行步骤进行操作,启动dubbo admin server和dubbo admin ui。
3、运行dubbo admin server,dubbo admin server是一个标准的spring boot项目, 可以在任何java IDE中运行它。
4、运行dubbo admin ui,dubbo admin ui由npm管理和构建,在开发环境中,可以单独运行: npm run dev。
5、官方git仓库dubbo下载dubbo源码并切换分支到dubbo-2.7.4.1的分支。
6、启动org.apache.dubbo.demo.provider.Application作为provider运行。
7、启动org.apache.dubbo.demo.consumer.Application作为consumer运行。
8、整个调试过程中请自行启动zookeeper作为注册中心,并修改provider和consumer的注册中心地址。
9、其他的实际请自行打断点进行debug操作。