dubbo系列之zookeeper订阅节点
源码构成
RegistryProtocol类
1 | registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);//订阅节点 |
FailbackRegistry类
subscribe()——向服务端发送订阅请求,及异常情况进行订阅重试
1 | public void subscribe(URL url, NotifyListener listener) { |
ZookeeperRegistry类
doSubscribe()
1 | else { |
List children = zkClient.addChildListener(path, zkListener);//为该节点设置监听
–>AbstractZookeeperClient.addChildListener
-->createTargetChildListener(path, listener)//收到订阅后的处理,交给FailbackRegistry.notify处理
–>ZkclientZookeeperClient.createTargetChildListener
–>new IZkChildListener()
–>实现了 handleChildChange //收到订阅后的处理
–>listener.childChanged(parentPath, currentChilds)
1 | public IZkChildListener createTargetChildListener(String path, final ChildListener listener) { |
–>AbstractZookeeperClient.addChildListener
-->addTargetChildListener(path, targetListener);
——启动加入订阅/dubbo/com.alibaba.dubbo.demo.DemoService/configurators
1 | public List<String> addTargetChildListener(String path, final IZkChildListener listener) { |
FailbackRegistry.notify
1 | protected void notify(URL url, NotifyListener listener, List<URL> urls) { |
doNotify(url, listener, urls);
-->AbstractRegistry.notify
–>saveProperties(url);——将服务端的注册信息更新到本地缓存文件中
1 | private void saveProperties(URL url) { |
进入线程池看一看
AbstractRegistry类
doSaveProperties()
1 | try { |
配置文件更新完之后
RegistryProtocol类
—->OverrideListener
---->notify()
1 | public void notify(List<URL> urls) { |
对比新旧的信息是否有变化,有则重新暴露服务.
最后来一张zookeeper订阅节点流程图,看完就更清晰了