Dubbo原始碼之服務引用

擊水三千里發表於2019-03-28
服務引用-整體架構設計圖
ReferenceBean.getObject()
  -->ReferenceConfig.get()
    -->init()
      -->createProxy(map)
        -->refprotocol.refer(interfaceClass, urls.get(0))
          -->ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("registry");
          -->extension.refer(arg0, arg1);
            -->ProtocolFilterWrapper.refer
              -->RegistryProtocol.refer
                -->registryFactory.getRegistry(url)//建立zk的連線,和服務端釋出一樣(省略程式碼)
                -->doRefer(cluster, registry, type, url)
                  -->registry.register//建立zk的節點,和服務端釋出一樣(省略程式碼)。節點名為:dubbo/com.alibaba.dubbo.demo.DemoService/consumers
                  -->registry.subscribe//訂閱zk的節點,和服務端釋出一樣(省略程式碼)。   /dubbo/com.alibaba.dubbo.demo.DemoService/providers, 
                                                                        /dubbo/com.alibaba.dubbo.demo.DemoService/configurators,
                                                                         /dubbo/com.alibaba.dubbo.demo.DemoService/routers]
                    -->notify(url, listener, urls);
                      -->FailbackRegistry.notify
                        -->doNotify(url, listener, urls);
                          -->AbstractRegistry.notify
                            -->saveProperties(url);//把服務端的註冊url資訊更新到C:\Users\bobo\.dubbo\dubbo-registry-192.168.48.117.cache
	                          -->registryCacheExecutor.execute(new SaveProperties(version));//採用執行緒池來處理
	                        -->listener.notify(categoryList)
	                          -->RegistryDirectory.notify
	                            -->refreshInvoker(invokerUrls)//重新整理快取中的invoker列表
	                              -->destroyUnusedInvokers(oldUrlInvokerMap,newUrlInvokerMap); // 關閉未使用的Invoker
	                              -->最終目的:重新整理Map<String, Invoker<T>> urlInvokerMap 物件
	                                                                                                                       重新整理Map<String, List<Invoker<T>>> methodInvokerMap物件
                  -->cluster.join(directory)//加入叢集路由
                    -->ExtensionLoader.getExtensionLoader(com.alibaba.dubbo.rpc.cluster.Cluster.class).getExtension("failover");
                      -->MockClusterWrapper.join
                        -->this.cluster.join(directory)
                          -->FailoverCluster.join
                            -->return new FailoverClusterInvoker<T>(directory)
                            -->new MockClusterInvoker
        -->proxyFactory.getProxy(invoker)//建立服務代理
          -->ProxyFactory$Adpative.getProxy
            -->ExtensionLoader.getExtensionLoader(com.alibaba.dubbo.rpc.ProxyFactory.class).getExtension("javassist");
              -->StubProxyFactoryWrapper.getProxy
                -->proxyFactory.getProxy(invoker)
                  -->AbstractProxyFactory.getProxy
                    -->getProxy(invoker, interfaces)
                      -->Proxy.getProxy(interfaces)//目前代理物件interface com.alibaba.dubbo.demo.DemoService, interface com.alibaba.dubbo.rpc.service.EchoService
                      -->InvokerInvocationHandler// 採用jdk自帶的InvocationHandler,建立InvokerInvocationHandler物件。
	                          
	                          
                    
   


灰度釋出例子:

provider 192.168.100.38   192.168.48.32

1.釋出192.168.48.32,切斷192.168.48.32訪問流量,然後進行服務的釋出。

2.192.168.48.32釋出成功後,恢復 192.168.48.32的流量,

3.切斷192.168.100.38,繼續釋出 192.168.100.38

相關文章