Pigeon细节梳理之ZK里存了什么

在ZK的DP/SERVER节点下

CuratorRegistry #  registerPersistentNode

void registerPersistentNode(String serviceName, String group, String serviceAddress, int weight)
            throws RegistryException {
        String weightPath = Utils.getWeightPath(serviceAddress);
        String servicePath = Utils.getServicePath(serviceName, group);
        try {
            if (client.exists(servicePath, false)) {
                Stat stat = new Stat();
                String addressValue = client.getWithNodeExistsEx(servicePath, stat);
                String[] addressArray = addressValue.split(",");
                List<String> addressList = new ArrayList<String>();
                for (String addr : addressArray) {
                    addr = addr.trim();
                    if (addr.length() > 0 && !addressList.contains(addr)) {
                        addressList.add(addr.trim());
                    }
                }
                if (!addressList.contains(serviceAddress)) {
                    addressList.add(serviceAddress);
                    Collections.sort(addressList);
                    client.set(servicePath, StringUtils.join(addressList.iterator(), ","), stat.getVersion());//如果是多个多个ip:port用逗号隔开
                }
            } else {
                client.create(servicePath, serviceAddress);//如果只有一个服务提供者就是一个字符串
            }
            ......

 RPC之美团pigeon源码分析(三)调用方服务监听和调用 - 简书 (jianshu.com)

posted on 2021-05-21 16:04  MaXianZhe  阅读(56)  评论(0编辑  收藏  举报

导航