Dubbo-服务提供者向Zookeeper注册了什么

33 篇文章 0 订阅
服务提供者

在启动时会调用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&timestamp=1596679754245
  1. 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),

  1. 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&timestamp=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中的

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值