dubbo registry 基本流程

来源:互联网 发布:java volatile用法 编辑:程序博客网 时间:2024/06/14 23:26

阅读源码,了解了一下registry基本流程,做个记录。以zookeeper为例。

Registry的基本类图


notifyListener的基本类图


流程说明:

1.      首先RegistryService定义了一些接口

2.      AbstractRegistry

有一个保存缓存文件的定时器,定时写入本地文件。

定义了3个属性,registered,subscribed,notified,当有url进行注册的时候,会调用对应的注册方法,订阅方法,通知方法。Notify方法里面会调用NotifyListener的notify方法,provider和consumer有不同的listener实现,见上图。

3.      FallbackRegistry

提供容错功能。

提供一个重试的定时器。会定时的把注册失败,解除注册失败,订阅失败,取消订阅失败的url进行retry操作。

并提供了模板方法供子类实现具体的注册,订阅等逻辑。

// ==== 模板方法 ====

   protectedabstract void doRegister(URLurl);

   protectedabstract void doUnregister(URLurl);

    protectedabstract void doSubscribe(URLurl, NotifyListener listener);    

protectedabstract void doUnsubscribe(URLurl, NotifyListener listener);

4.       ZookeeperRegistry

构造函数中会注册一个StateListener,当zk挂掉然后链接到其他server的时候,会执行recover机制,会把已注册的和已订阅的url添加到对应的注册失败和订阅失败的set和map中,后续有上面#3提供的retry机制保证重连到新server。

doSubscribe方法。会添加一个ChildListener,当前节点的子节点变化时会触发,然后调用notify。

经测试

当前目录 /dubbo/com.lp.techDemo.dubbo.sharedService.RemoteService/providers

下面有节点http%3A%2F%2F10.106.131.8%3A8083%2Fcom.lp.techDemo.dubbo.sharedService.RemoteService%3Faccesslog%3DE%3A%2Flog%2Fdubbo%2Fremote-access.log%26anyhost%3Dtrue%26application%3Dhello-world-app%26dubbo%3D2.5.4-SNAPSHOT%26generic%3Dfalse%26interface%3Dcom.lp.techDemo.dubbo.sharedService.RemoteService%26methods%3DsaySomething%26pid%3D6444%26side%3Dprovider%26timestamp%3D1465380936455

更改这个节点的值不会触发上面的ChildListener,删除这个节点,会触发listener。

但是删除节点会导致consumer无法访问。

com.alibaba.dubbo.rpc.RpcException: Forbid consumer 127.0.0.1 access servicecom.lp.techDemo.dubbo.sharedService.RemoteService from registry 127.0.0.1:2181use dubbo version 2.5.4-SNAPSHOT, Please check registry access list(whitelist/blacklist).

没搞明白这个listener还有啥用处,后续再看看吧。



0 0