服务提供者
在启动时会调用ZookeeperRegistry#中
@Override
public void doRegister(URL url) {
try {
//创建节点
zkClient.create(toUrlPath(url), url.getParameter(DYNAMIC_KEY, true));
} catch (Throwable e) {
throw new RpcException("Failed to register " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
}
}
- 完整的url
dubbo://10.18.200.149:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello,sayHelloAsync&pid=7764&release=&side=provider×tamp=1596679754245
- url.getParameter(DYNAMIC_KEY, true)
String DYNAMIC_KEY = "dynamic";
意思判断url中有没有这个参数,有就使用URL中的参数值,没有就默认true, url中默认也是true
void create(String path, boolean ephemeral);
这里表示创建的是临时节点 ,服务提供者的接口org.apache.dubbo.demo.DemoService
toUrlPath(url),
- toUrlPath(url),节点名称
private String toUrlPath(URL url) {
return toCategoryPath(url) + PATH_SEPARATOR + URL.encode(url.toFullString());
}
PATH_SEPARATOR 就是 “/”
- url.toFullString()
dubbo://10.18.200.149:20880/org.apache.dubbo.demo.DemoService?anyhost=true&application=demo-provider&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=org.apache.dubbo.demo.DemoService&metadata-type=remote&methods=sayHello,sayHelloAsync&pid=7764&release=&side=provider×tamp=1596679754245
- toCategoryPath
private String toCategoryPath(URL url) {
//category getParameter获取这个参数值,没有就用 providers
//PATH_SEPARATOR 就是/
return toServicePath(url) + PATH_SEPARATOR + url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
}
- toServicePath
返回 /dubbo/org.apache.dubbo.demo.DemoService
private String toServicePath(URL url) {
//org.apache.dubbo.demo.DemoService 接口名称
String name = url.getServiceInterface();
//判断 名称是否为*
if (ANY_VALUE.equals(name)) {
return toRootPath();
}
return toRootDir() + URL.encode(name);
}
- toRootDir–/dubbo
private String toRootDir() {
if (root.equals(PATH_SEPARATOR)) {
return root;
}
return root + PATH_SEPARATOR;
}
/dubbo/org.apache.dubbo.demo.DemoService
最终的path
/dubbo/org.apache.dubbo.demo.DemoService/providers/dubbo%3A%2F%2F10.18.200.149%3A20880%2Forg.apache.dubbo.demo.DemoService%3Fanyhost%3Dtrue%26application%3Ddemo-provider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dorg.apache.dubbo.demo.DemoService%26metadata-type%3Dremote%26methods%3DsayHello%2CsayHelloAsync%26pid%3D7764%26release%3D%26side%3Dprovider%26timestamp%3D1596679754245
/dubbo/org.apache.dubbo.demo.DemoService/providers/dubbo%3A%2F%2F10.18.200.149%3A20880%2Forg.apache.dubbo.demo.DemoService%3Fanyhost%3Dtrue%26application%3Ddemo-provider%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dorg.apache.dubbo.demo.DemoService%26metadata-type%3Dremote%26methods%3DsayHello%2CsayHelloAsync%26pid%3D7764%26release%3D%26side%3Dprovider%26timestamp%3D1596679754245
- /dubbo 是根据节点,dubbot启动时自己创建,命名空间
- org.apache.dubbo.demo.DemoService 接口全路径
- providers 表明是服务提供者
- 最后就是完整的url,ecnding之后
看下zk中的