Dubbo原始碼解讀02客戶端註冊釋出過程
客戶端服務註冊釋出主要做了以下幾件事
1.讀取配置檔案,封裝map
2.讀取zk中providers,生成netty連線,放入urlInvokerMap,將本身consumer註冊到zk
3.根據配置檔案ref,生成proxy客戶端代理
4.通過proxy代理呼叫urlInvokerMap中的invoker通過netty連線傳送請求,取得返回結果
下面是整個程式碼呼叫流程
ReferenceBean.afterPropertiesSet()-->getObject()-->get()
ReferenceConfig.get()-->init()-->createProxy()
init()拼裝xml對應引數map
createProxy()
invoker=RegistryProtocol.refer()=MockClusterInvoker
proxyFactory.getProxy(invoker)=JavassistProxyFactory.getProxy(invoker)=proxy0
proxy0是服務代理(客戶端呼叫的實現類)
method sayHello
handle.invoke()
handel = InvokerInvocationHandler(invoker)
RegistryProtocol.refer()
doRefer()
directory.subscribe()
RegistryDirectory.subscribe()
cluster=MockClusterWrapper()
cluster.join(directory)==MockClusterInvoker()
RegistryDirectory.subscribe()
registry === zookeeperRegistry RegistryProtocol中set的值
registry.subscribe(url, this);//consumer:// this:RegistryDirectory
RegistryDirectory.subscribe()-->FailbackRegistry.subscribe()-->ZookeeperRegistry.doSubscribe()-->notify()-->doNotify()-->AbstractRegistry.notify()-->listener.notify(categoryList);
listener = RegistryDirectory
RegistryDirectory.notify()-->refreshInvoker()-->toInvokers(invokerUrls)
invoker = new InvokerDelegete<T>(protocol.refer(serviceType, url), url, providerUrl);
protocol=DubboProtocol
protocol.refer(serviceType, url)
DubboProtocol.refer()
DubboInvoker<T> invoker = new DubboInvoker<T>(serviceType, url, getClients(url), invokers);
getClients(url)//生成netty客戶端連線
initClient()
client = Exchangers.connect(url ,requestHandler);