• dubbo 学习


    dubbo provider、consumer启动的时候,如果没有指定协议,则默认是dubbo协议,对应代码如下:

    String name = protocolConfig.getName();
    if (name == null || name.length() == 0) {
    name = "dubbo";
    }

    -------------------------------------------------------------------------------
    dubbo注册到zookeeper中,节点是持久化的节点来的,节点如下:
    [dubbo%3A%2F%2F10.100.97.26%3A20881%2Fcom.drafire.user.IUserService%3Fapplication%3Duser-provider%26dubbo%3D2.5.3%26interface%3Dcom.drafire.user.IUserService%26methods%3Dlogin%26owner%3Ddrafire%26pid%3D21568%26side%3Dprovider%26timestamp%3D1552035568717]

    解码后如下:

    [dubbo://10.100.97.26:20881/com.drafire.user.IUserService?application=user-provider&dubbo=2.5.3&interface=com.drafire.user.IUserService&methods=login&owner=drafire&pid=21568&side=provider&timestamp=1552035568717]

    从这里可以看出,这个是一个无序的节点,因为有序的节点建立后,节点后面会有一串数字,数字从:10000000000 开始。如下所示:

    [zk: localhost:2181(CONNECTED) 32] create -s /test/node1 abc
    Created /test/node10000000000

    查看该节点的性质: get /dubbo/com.drafire.user.IUserService/providers,结果如下:

    null
    cZxid = 0x400000004
    ctime = Fri Mar 08 00:59:43 PST 2019
    mZxid = 0x400000004
    mtime = Fri Mar 08 00:59:43 PST 2019
    pZxid = 0x400000005
    cversion = 1
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 0
    numChildren = 1

    从这里可以看出,这个是持久化节点。如果是临时节点,这了会有个临时拥有者,是一串数字并且值大于0

    从源码也可以看出是新建的持久化非有序节点,代码如下:
    // comalibabadubbo2.5.3dubbo-2.5.3-sources.jar!comalibabadubbo
    egistryzookeeperookeeperRegistry.java
    protected void doSubscribe(final URL url, final NotifyListener listener) { try { if (Constants.ANY_VALUE.equals(url.getServiceInterface())) { String root = toRootPath(); ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(url); if (listeners == null) { zkListeners.putIfAbsent(url, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(url); } ChildListener zkListener = listeners.get(listener); if (zkListener == null) { listeners.putIfAbsent(listener, new ChildListener() { public void childChanged(String parentPath, List<String> currentChilds) { for (String child : currentChilds) { if (! anyServices.contains(child)) { anyServices.add(child); subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child, Constants.CHECK_KEY, String.valueOf(false)), listener); } } } }); zkListener = listeners.get(listener); } zkClient.create(root, false); List<String> services = zkClient.addChildListener(root, zkListener); if (services != null && services.size() > 0) { anyServices.addAll(services); for (String service : services) { subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service, Constants.CHECK_KEY, String.valueOf(false)), listener); } } } else { List<URL> urls = new ArrayList<URL>(); for (String path : toCategoriesPath(url)) { ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(url); if (listeners == null) { zkListeners.putIfAbsent(url, new ConcurrentHashMap<NotifyListener, ChildListener>()); listeners = zkListeners.get(url); } ChildListener zkListener = listeners.get(listener); if (zkListener == null) { listeners.putIfAbsent(listener, new ChildListener() { public void childChanged(String parentPath, List<String> currentChilds) { ZookeeperRegistry.this.notify(url, listener, toUrlsWithEmpty(url, parentPath, currentChilds)); } }); zkListener = listeners.get(listener); } zkClient.create(path, false); //这里创建了持久化的非有序节点 List<String> children = zkClient.addChildListener(path, zkListener); if (children != null) { urls.addAll(toUrlsWithEmpty(url, path, children)); } } notify(url, listener, urls); } } catch (Throwable e) { throw new RpcException("Failed to subscribe " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e); } }



  • 相关阅读:
    Javaweb开发环境与搭建
    剑指Offer:面试题32——从1到n整数中1出现的次数(java实现)
    剑指Offer:面试题31——连续子数组的最大和(java实现)
    剑指Offer:面试题30——最小的k个数(java实现)
    剑指Offer:面试题29——数组中出现次数超过一半的数字(java实现)
    剑指Offer:解决难题时的三大方法
    剑指Offer:面试题28——字符串的排列(java实现)(待序)
    剑指Offer:面试题27——二叉搜索树与双向链表(java实现)
    剑指Offer:面试题26——复制复杂的链表(java实现)
    剑指Offer:面试题25——二叉树中和为某一值的路径(java实现)
  • 原文地址:https://www.cnblogs.com/drafire/p/9935911.html
Copyright © 2020-2023  润新知