首页 > 其他 > 详细

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

时间:2021-05-21 17:41:19      阅读:29      评论:0      收藏:0      [点我收藏+]

在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);//如果只有一个服务提供者就是一个字符串
            }
            ......

 

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

原文:https://www.cnblogs.com/juniorMa/p/14794196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!