Dubbo源码解读02客户端注册发布过程

客户端服务注册发布主要做了以下几件事

1.读取配置文件,封装map

2.读取zk中providers,生成netty连接,放入urlInvokerMap,将本身consumer注册到zk

3.根据配置文件ref,生成proxy客户端代理

4.通过proxy代理调用urlInvokerMap中的invoker里面的client通过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);//心跳机制、生成netty连接

客户端调用过程

interface.method()//接口.调用方法名

proxy0.method()

handle.invoke()

InvokerInvocationHandler.invoke()

MockClusterInvoker.invoke()

AbstractClusterInvoker().invoke()

FailOverClusterInvoker.doInvoke()

AbstractInvoker.invoke()

DubboInvoker.doInvoke()

......

NettyChnnel.send()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值