Dubbo-服务发布

  Dubbo服务端启动步骤:

    1.Export dubbo service 暴露本地服务

 main  INFO config.AbstractConfig:  [DUBBO] Export dubbo service com.alibaba.dubbo.demo.DemoService to local registry, dubbo version: , current host: 192.168.10.1

    2.Register dubbo service 暴露远程服务

 main  INFO config.AbstractConfig:  [DUBBO] Export dubbo service com.alibaba.dubbo.demo.DemoService to url dubbo://192.168.10.1:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bean.name=com.alibaba.dubbo.demo.DemoService&bind.ip=192.168.10.1&bind.port=20880&dubbo=2.0.2&generic=false&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=52884&qos.port=22222&side=provider&timestamp=1588143599790, dubbo version: , current host: 192.168.10.1

 main  INFO config.AbstractConfig:  [DUBBO] Register dubbo service com.alibaba.dubbo.demo.DemoService url dubbo://192.168.10.1:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bean.name=com.alibaba.dubbo.demo.DemoService&bind.ip=192.168.10.1&bind.port=20880&dubbo=2.0.2&generic=false&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=52884&qos.port=22222&side=provider&timestamp=1588143599790 to registry registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-provider&dubbo=2.0.2&pid=52884&qos.port=22222&registry=zookeeper&timestamp=1588143599751, dubbo version: , current host: 192.168.10.1

    3.Start NettyServer 启动netty

 main  INFO transport.AbstractServer:  [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /192.168.10.1:20880, dubbo version: , current host: 192.168.10.1

    4.zookeeper.ClientCnxn:opening socket  打开链接zk

 main-SendThread(127.0.0.1:2181)  INFO zookeeper.ClientCnxn: Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

    5.ZookeeperRegistry:到zk注册

 main INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: dubbo://192.168.10.1:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bean.name=com.alibaba.dubbo.demo.DemoService&dubbo=2.0.2&generic=false&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=52884&side=provider&timestamp=1588143599790, dubbo version: , current host: 192.168.10.1
 main-SendThread(127.0.0.1:2181) INFO zookeeper.ClientCnxn: Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x171ab21a20e0020, negotiated timeout = 40000

    6.Subscribe   监听zk

 main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Subscribe: provider://192.168.10.1:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bean.name=com.alibaba.dubbo.demo.DemoService&category=configurators&check=false&dubbo=2.0.2&generic=false&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=52884&side=provider&timestamp=1588143599790, dubbo version: , current host: 192.168.10.1

源码分析:

Dubbo-服务发布

 Dubbo-服务发布

 Dubbo-服务发布

   找对对应的ServiceBean类,发现实现了ApplicationListener接口实现了onApplicationEvent方法,调用了export()方法

Dubbo-服务发布

 调用继承类ServiceConfig方法export()

Dubbo-服务发布

 暴露服务

Dubbo-服务发布

   暴露本地服务:只暴露在同一个JVM里面,不用通过zk来进行远程通信。例如:同一个服务,自己调用用自己接口,就没必要进行网路ip链接通讯

暴露远程服务:指暴露给远程客户端的ip和端口号,通过网络实通信

Dubbo-服务发布

ServiceBean.onApplicationEvent

  -->export()

    -->ServiceConfig.export()

      -->doExport()

        -->doExportUrls()  //<dubbo:protocol name="dubbo" port="20880" id="dubbo" />

          -->loadRegistries(ture)  // 从dubbo配置文件组装registry的url信息   registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-provider&dubbo=2.0.2&pid=55548&qos.port=22222&registry=zookeeper&timestamp=1588146544281

          -->doExportUrlsFor1Protocol //暴露服务

            -->exportLocal(url)//暴露本地服务

              -->proxyFactory.getInvoker(ref, (Class) interfaceClass, local));

                -->JavassitPorxyFactory.getInvoker

                  -->Wrapper.getWrapper

                    -->makeWrapper  

                  -->return new AbstractProxyInvoker

1.proxyFactory:就是为了获取一个接口的代理类,例如获取一个远程接口的代理

  getInvoker:针对server端,将服务对象,例如DemoServiceImpl包装成一个Invoker对象

  getProxy:针对client端,创建接口的的代理对象。例如DemoService的接口

2.Wrapper:类似springde BeanWrapper,包装了一个接口或者一个类,可以通过wrapper对实例对象进行赋值、取值以及指定方法调用

3.Invoker:它是一个可执行的对象,能够根据方法的名称、参数得到相应的执行结果

    Result invoke(Invocation invocation)       Invocation包含了需要执行的方法和参数等信息,有两个实现类RpcInvocation和MockInvocation 三种类型的Invoker  1.本地执行类的Invoker  2.远程调用类的Invoker  3.多个远程通信执行类的Invoker聚合成集群版的Invoker

--

--