服务引用-整体架构设计图
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