Dubbo Service Reference Principle

Keywords: Dubbo JDK

Dubbo Service Reference Principle

 

Service reference principle, first look at the code call logic, and then step-by-step debug.

Consumer References:
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)//The connection of zk is the same as that of server publishing (omitting code).
                -->doRefer(cluster, registry, type, url)
                  -->registry.register//Create the node of zk, just like the server publishing (omit the code). Node name: dubbo/com.alibaba.dubbo.demo.DemoService/consumers
                  -->registry.subscribe//The node subscribing to zk is the same as the server-side publishing (omitting code). /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);//Update the registration url information of the server to C:\Users\bobo\.dubbo\dubbo-registry-192.168.48.117.cache.
                             -->registryCacheExecutor.execute(new SaveProperties(version));//Use thread pool to process
                           -->listener.notify(categoryList)
                             -->RegistryDirectory.notify
                               -->refreshInvoker(invokerUrls)//Refresh the list of invoker s in the cache
                                 -->destroyUnusedInvokers(oldUrlInvokerMap,newUrlInvokerMap); // Close unused Invoker
                                 -->Ultimate goal: refresh Map<String, Invoker<T>> urlInvokerMap object
                                                                                                                          //Refresh map < string, list < invoker < T > > > methodinvokermap object
                  -->cluster.join(directory)//Join cluster routing
                    -->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)//Create service agent
          -->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)//Currently, the proxy object interface com.alibaba.dubbo.demo.demo service, interface com.alibaba.dubbo.rpc.service.echoservice
                      -->InvokerInvocationHandler// The InvocationHandler provided by jdk is used to create the InvokerInvocationHandler object.

 

First, the init method of ReferenceConfig class calls the refer method of Protocol to generate the Invoker instance (as shown in the red part in the figure above), which is the key to service consumption.

Next, convert the Invoker to the interface required by the client (such as HelloWorld).

 

 

 

1.

 

 

 

 

 

 

 

 

Next is the key

 

 

 

 

 

 

 

 

 

 

 

Subscription consumer

 

 

 

 

 

 

The above lines are because notify will be triggered after subscribe

 

 

 

Adopt the failfast strategy

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted by inosent1 on Thu, 31 Oct 2019 04:11:05 -0700