dubbo3.0引用源码简版
2023-11-14 16:16:06 0 举报
dubbo3.0引用源码简版
作者其他创作
大纲/内容
org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster#buildClusterInterceptors
org.apache.dubbo.config.ReferenceConfig#createInvokerForRemote
org.apache.dubbo.registry.client.migration.MigrationInvoker#refreshServiceDiscoveryInvoker
org.apache.dubbo.rpc.cluster.support.FailoverCluster#doJoin
2
2创建MockClusterInvoker对象,它里面包含了ClusterFilterInvoker对象和ServiceDiscoveryRegistryDirectory对象
生成一个MetadataService代理对象,是个消费者,它去服务端的MetadataService服务通信那是怎么知道服务端的这个MetadataService的端口是多少呢?生成MetadataService代理对象
1
在这里面遍历dubbo-springboot-demo-provider节点的元数据
1.1、构造一个MetadataService客户端
org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory#toInvokers
org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener#onEvent
从/services/dubbo-springboot-demo-provider/192.168.124.10:20880和/services/dubbo-springboot-demo-provider/192.168.124.10:20881节点下,获取应用的元数据因为dubbo-springboot-demo-provider有可能是集群部署也就是多个实例,也就是获取所有dubbo-springboot-demo-provider应用的元数据
org.apache.dubbo.registry.integration.RegistryProtocol#doCreateInvoker
1、生成所有符合当前消费者的,已经和客户端建立好连接的invoker
[ { \"name\": \"dubbo-springboot-demo-provider\
org.apache.dubbo.registry.client.metadata.MetadataUtils#getRemoteMetadata
org.apache.dubbo.registry.client.ServiceDiscoveryRegistry#subscribeURLs
currentAvailableInvoker = serviceDiscoveryInvoker;
返回
设置到org.apache.dubbo.rpc.cluster.directory.AbstractDirectory#invokers属性中
org.apache.dubbo.rpc.cluster.directory.AbstractDirectory#setInvokers
调用代理对象的org.apache.dubbo.metadata.MetadataService#getMetadataInfo方法
org.apache.dubbo.registry.client.migration.MigrationInvoker#calcPreferredInvoker
org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener#doOnEvent
1 接口级别的引用
将MetadataService对象转化成ProtocolServiceKeyWithUrls对象放到org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener#serviceUrls里面
org.apache.dubbo.registry.client.migration.MigrationInvoker#migrateToApplicationFirstInvoker
返回FailoverClusterInvoker对象
org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster.ClusterFilterInvoker#ClusterFilterInvoker
org.apache.dubbo.registry.client.metadata.MetadataUtils#referProxy
org.apache.dubbo.registry.integration.RegistryProtocol#doRefer
org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory#refreshInvoker
3、决定用接口级别的引用还是应用级别的引用
2应用级别的引用
将应用级的invoker赋值给currentAvailableInvoker
返回ClusterFilterInvoker对象
返回FailoverClusterInvoker,它里面有负载均衡的逻辑且包含了ServiceDiscoveryRegistryDirectory,ServiceDiscoveryRegistryDirectory里面包含了获取的invoker对象
org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener#addListenerAndNotify
org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory#subscribe
在这里根据SPI生成消费端过滤器链放到org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster.ClusterFilterInvoker#filterInvoker属性中,对象是ClusterCallbackRegistrationInvoker,这个对象里面有FailoverClusterInvoker对象和所有的拦截器对象
3
org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster#join
org.apache.dubbo.registry.integration.InterfaceCompatibleRegistryProtocol#getServiceDiscoveryInvoker
返回DubboInvoker
作为入参传入
org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker
获取79af34d6be7b9bb1234eed8330d10124上面的,所有接口级服务的所有元数据
List<ServiceInstance>
那必须是这里的port
赋值给serviceDiscoveryInvoker属性
org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory#notify
{ \"app\": \"dubbo-springboot-demo-provider\
org.apache.dubbo.registry.client.migration.MigrationInvoker#refreshInterfaceInvoker
org.apache.dubbo.rpc.Protocol#refer
ListenerInvokerWrapper
org.apache.dubbo.metadata.MetadataService#getMetadataInfo
org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol#refer
进行过滤,匹配出符合当前消费者的服务提供者
org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterWrapper#join
将返回结果包装
org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster#buildInterceptorInvoker
0 条评论
回复 删除
下一页