【Dubbo】启动流程

下图是dubbo的一个整体架构,其中包含了Registry,Consumer,Provider,Monitor等角色。但是可能我们都有一些疑问,比如:这么多角色每个角色的作用是什么?他们是怎么联系起来形成一个整体,如何它们之间是怎么交互的?

image.png

下面我们可以通过dubbo的启动日志来探究一下dubbo的启动流程找到这些问题的答案。

启动日志

在Provider和Consumner日志中标出了启动流程:

  • Provider启动日志
1.本地暴露
[14/06/18 11:16:50:050 CST] main  INFO config.AbstractConfig:  [DUBBO] Export dubbo service com.alibaba.dubbo.demo.DemoService to local registry, dubbo version: 2.0.0, current host: 192.168.99.2

2.远程暴露
[14/06/18 11:16:50:050 CST] main  INFO config.AbstractConfig:  [DUBBO] Export dubbo service com.alibaba.dubbo.demo.DemoService to url dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.99.2&bind.port=20881&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&qos.port=22222&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:16:50:050 CST] main  INFO config.AbstractConfig:  [DUBBO] Register dubbo service com.alibaba.dubbo.demo.DemoService url dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.99.2&bind.port=20881&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&qos.port=22222&side=provider&threadpool=cached&threads=5&timestamp=1528946210558 to registry registry://47.94.102.25:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-provider&dubbo=2.0.0&owner=wliliam&pid=7372&qos.port=22222&registry=zookeeper&timestamp=1528946210549, dubbo version: 2.0.0, current host: 192.168.99.2

3.启动netty
[14/06/18 11:16:51:051 CST] main  INFO transport.AbstractServer:  [DUBBO] Start NettyServer bind /0.0.0.0:20881, export /192.168.99.2:20881, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:16:51:051 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Load registry store file C:\Users\pengyunlong\.dubbo\dubbo-registry-demo-provider-47.94.102.25:2181.cache, data: {com.alibaba.dubbo.demo.DemoService=override://192.168.0.1/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&weight=6 override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&mock=fail%3Areturn+null override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&loadbalance=random}, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:16:51:051 CST] main  INFO imps.CuratorFrameworkImpl: Starting
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:host.name=DESKTOP-DM62SEC
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_80
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.home=C:\Program Files\Java\jdk1.7.0_80\jre
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.class.path=C:\Program Files\Java\jdk1.7.0_80\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\rt.jar;E:\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-provider\target\classes;E:\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-container\dubbo-container-spring\target\classes;E:\dubbo\incubator-dubbo\dubbo-container\dubbo-container-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-common\target\classes;C:\Users\pengyunlong\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\pengyunlong\.m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar;C:\Users\pengyunlong\.m2\repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-context\4.3.10.RELEASE\spring-context-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-aop\4.3.10.RELEASE\spring-aop-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-core\4.3.10.RELEASE\spring-core-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-expression\4.3.10.RELEASE\spring-expression-4.3.10.RELEASE.jar;E:\dubbo\incubator-dubbo\dubbo-config\dubbo-config-spring\target\classes;E:\dubbo\incubator-dubbo\dubbo-config\dubbo-config-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-monitor\dubbo-monitor-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-validation\target\classes;C:\Users\pengyunlong\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;E:\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-cache\target\classes;C:\Users\pengyunlong\.m2\repository\javax\cache\cache-api\1.0.0\cache-api-1.0.0.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-beans\4.3.10.RELEASE\spring-beans-4.3.10.RELEASE.jar;E:\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-injvm\target\classes;E:\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-zookeeper\target\classes;E:\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-cluster\target\classes;E:\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-zookeeper\target\classes;C:\Users\pengyunlong\.m2\repository\org\apache\zookeeper\zookeeper\3.4.9\zookeeper-3.4.9.jar;C:\Users\pengyunlong\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\pengyunlong\.m2\repository\org\slf4j\slf4j-log4j12\1.6.1\slf4j-log4j12-1.6.1.jar;C:\Users\pengyunlong\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\pengyunlong\.m2\repository\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar;C:\Users\pengyunlong\.m2\repository\com\101tec\zkclient\0.2\zkclient-0.2.jar;C:\Users\pengyunlong\.m2\repository\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;C:\Users\pengyunlong\.m2\repository\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;C:\Users\pengyunlong\.m2\repository\com\google\guava\guava\16.0.1\guava-16.0.1.jar;E:\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-multicast\target\classes;E:\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-dubbo\target\classes;E:\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-netty\target\classes;C:\Users\pengyunlong\.m2\repository\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;E:\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-hessian2\target\classes;E:\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-api\target\classes;C:\Users\pengyunlong\.m2\repository\com\alibaba\fastjson\1.2.46\fastjson-1.2.46.jar;C:\Users\pengyunlong\.m2\repository\com\esotericsoftware\kryo\4.0.1\kryo-4.0.1.jar;C:\Users\pengyunlong\.m2\repository\com\esotericsoftware\reflectasm\1.11.3\reflectasm-1.11.3.jar;C:\Users\pengyunlong\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\pengyunlong\.m2\repository\com\esotericsoftware\minlog\1.3.0\minlog-1.3.0.jar;C:\Users\pengyunlong\.m2\repository\de\javakaffee\kryo-serializers\0.42\kryo-serializers-0.42.jar;C:\Users\pengyunlong\.m2\repository\de\ruedigermoeller\fst\2.48-jdk-6\fst-2.48-jdk-6.jar;C:\Users\pengyunlong\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.8.6\jackson-core-2.8.6.jar;C:\Users\pengyunlong\.m2\repository\com\cedarsoftware\java-util\1.9.0\java-util-1.9.0.jar;C:\Users\pengyunlong\.m2\repository\com\cedarsoftware\json-io\2.5.1\json-io-2.5.1.jar;E:\dubbo\incubator-dubbo\hessian-lite\target\classes;C:\Users\pengyunlong\.m2\repository\org\objenesis\objenesis\2.2\objenesis-2.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.3\lib\idea_rt.jar
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.library.path=C:\Program Files\Java\jdk1.7.0_80\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Oracle\product\11.2.0\client_1\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.7.0_80\bin;C:\Program Files\Java\jdk1.7.0_80\jre\bin;C:\Program Files\nodejs\;C:\ant-1.9.7\bin;C:\Program Files (x86)\Subversion\bin;C:\Program Files (x86)\apache-maven-3.5.0\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\gradle-4.0.2\bin;C:\Program Files (x86)\adb;C:\Users\pengyunlong\AppData\Local\Microsoft\WindowsApps;C:\Users\pengyunlong\AppData\Roaming\npm;C:\Program Files\Docker Toolbox;;.
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\PENGYU~1\AppData\Local\Temp\
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 8.1
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:os.version=6.3
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:user.name=pengyunlong
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\pengyunlong
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Client environment:user.dir=E:\dubbo
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZooKeeper: Initiating client connection, connectString=47.94.102.25:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@7d8bf453

4.连接zk
[14/06/18 11:16:52:052 CST] main-SendThread(47.94.102.25:2181)  INFO zookeeper.ClientCnxn: Opening socket connection to server 47.94.102.25/47.94.102.25:2181. Will not attempt to authenticate using SASL (unknown error)
[14/06/18 11:16:52:052 CST] main-SendThread(47.94.102.25:2181)  INFO zookeeper.ClientCnxn: Socket connection established to 47.94.102.25/47.94.102.25:2181, initiating session
[14/06/18 11:16:52:052 CST] main-SendThread(47.94.102.25:2181)  INFO zookeeper.ClientCnxn: Session establishment complete on server 47.94.102.25/47.94.102.25:2181, sessionid = 0x163da8bdb610099, negotiated timeout = 40000

5.到zk注册
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Register: dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:16:52:052 CST] main-EventThread  INFO state.ConnectionStateManager: State change: CONNECTED

6.监听configurators节点
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Subscribe: provider://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:16:52:052 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Notify urls for subscribe url provider://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, urls: [override://192.168.0.1/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&weight=6, override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&mock=fail%3Areturn+null, override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&loadbalance=random], dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:16:52:052 CST] main  INFO integration.RegistryProtocol:  [DUBBO] exported provider url changed, origin url: dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.99.2&bind.port=20881&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&qos.port=22222&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, old export url: dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.99.2&bind.port=20881&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&qos.port=22222&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, new export url: dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&bind.ip=192.168.99.2&bind.port=20881&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=random&methods=sayHello&mock=fail%3Areturn+null&owner=wliliam&pid=7372&qos.port=22222&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, dubbo version: 2.0.0, current host: 192.168.99.2
  • Consumer启动日志
[14/06/18 11:18:48:048 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Load registry store file C:\Users\pengyunlong\.dubbo\dubbo-registry-demo-consumer-47.94.102.25:2181.cache, data: {com.alibaba.dubbo.demo.DemoService=dubbo://192.168.99.2:20882/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=1556&side=provider&threadpool=cached&threads=5&timestamp=1528941502501 dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=1556&side=provider&threadpool=cached&threads=5&timestamp=1528941498619 override://192.168.0.1/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&weight=6 override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&mock=fail%3Areturn+null override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&loadbalance=random empty://192.168.99.2/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=routers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=consistenthash&methods=sayHello&pid=10628&qos.port=33333&side=consumer&timestamp=1528945871126}, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:18:48:048 CST] main  INFO imps.CuratorFrameworkImpl: Starting
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:host.name=DESKTOP-DM62SEC
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_80
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.home=C:\Program Files\Java\jdk1.7.0_80\jre
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.class.path=C:\Program Files\Java\jdk1.7.0_80\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_80\jre\lib\rt.jar;E:\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-consumer\target\classes;E:\dubbo\incubator-dubbo\dubbo-demo\dubbo-demo-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-config\dubbo-config-spring\target\classes;E:\dubbo\incubator-dubbo\dubbo-config\dubbo-config-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-monitor\dubbo-monitor-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-validation\target\classes;C:\Users\pengyunlong\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;E:\dubbo\incubator-dubbo\dubbo-filter\dubbo-filter-cache\target\classes;C:\Users\pengyunlong\.m2\repository\javax\cache\cache-api\1.0.0\cache-api-1.0.0.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-beans\4.3.10.RELEASE\spring-beans-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-core\4.3.10.RELEASE\spring-core-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-context\4.3.10.RELEASE\spring-context-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-aop\4.3.10.RELEASE\spring-aop-4.3.10.RELEASE.jar;C:\Users\pengyunlong\.m2\repository\org\springframework\spring-expression\4.3.10.RELEASE\spring-expression-4.3.10.RELEASE.jar;E:\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-injvm\target\classes;E:\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-zookeeper\target\classes;E:\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-cluster\target\classes;E:\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-zookeeper\target\classes;E:\dubbo\incubator-dubbo\dubbo-common\target\classes;C:\Users\pengyunlong\.m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar;C:\Users\pengyunlong\.m2\repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;C:\Users\pengyunlong\.m2\repository\org\apache\zookeeper\zookeeper\3.4.9\zookeeper-3.4.9.jar;C:\Users\pengyunlong\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\pengyunlong\.m2\repository\org\slf4j\slf4j-log4j12\1.6.1\slf4j-log4j12-1.6.1.jar;C:\Users\pengyunlong\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\pengyunlong\.m2\repository\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar;C:\Users\pengyunlong\.m2\repository\com\101tec\zkclient\0.2\zkclient-0.2.jar;C:\Users\pengyunlong\.m2\repository\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;C:\Users\pengyunlong\.m2\repository\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;C:\Users\pengyunlong\.m2\repository\com\google\guava\guava\16.0.1\guava-16.0.1.jar;E:\dubbo\incubator-dubbo\dubbo-registry\dubbo-registry-multicast\target\classes;E:\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-dubbo\target\classes;E:\dubbo\incubator-dubbo\dubbo-rpc\dubbo-rpc-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-container\dubbo-container-api\target\classes;E:\dubbo\incubator-dubbo\dubbo-remoting\dubbo-remoting-netty\target\classes;C:\Users\pengyunlong\.m2\repository\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;E:\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-hessian2\target\classes;E:\dubbo\incubator-dubbo\dubbo-serialization\dubbo-serialization-api\target\classes;C:\Users\pengyunlong\.m2\repository\com\alibaba\fastjson\1.2.46\fastjson-1.2.46.jar;C:\Users\pengyunlong\.m2\repository\com\esotericsoftware\kryo\4.0.1\kryo-4.0.1.jar;C:\Users\pengyunlong\.m2\repository\com\esotericsoftware\reflectasm\1.11.3\reflectasm-1.11.3.jar;C:\Users\pengyunlong\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\pengyunlong\.m2\repository\com\esotericsoftware\minlog\1.3.0\minlog-1.3.0.jar;C:\Users\pengyunlong\.m2\repository\de\javakaffee\kryo-serializers\0.42\kryo-serializers-0.42.jar;C:\Users\pengyunlong\.m2\repository\de\ruedigermoeller\fst\2.48-jdk-6\fst-2.48-jdk-6.jar;C:\Users\pengyunlong\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.8.6\jackson-core-2.8.6.jar;C:\Users\pengyunlong\.m2\repository\com\cedarsoftware\java-util\1.9.0\java-util-1.9.0.jar;C:\Users\pengyunlong\.m2\repository\com\cedarsoftware\json-io\2.5.1\json-io-2.5.1.jar;E:\dubbo\incubator-dubbo\hessian-lite\target\classes;C:\Users\pengyunlong\.m2\repository\org\objenesis\objenesis\2.2\objenesis-2.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.3\lib\idea_rt.jar
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.library.path=C:\Program Files\Java\jdk1.7.0_80\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Oracle\product\11.2.0\client_1\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.7.0_80\bin;C:\Program Files\Java\jdk1.7.0_80\jre\bin;C:\Program Files\nodejs\;C:\ant-1.9.7\bin;C:\Program Files (x86)\Subversion\bin;C:\Program Files (x86)\apache-maven-3.5.0\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\gradle-4.0.2\bin;C:\Program Files (x86)\adb;C:\Users\pengyunlong\AppData\Local\Microsoft\WindowsApps;C:\Users\pengyunlong\AppData\Roaming\npm;C:\Program Files\Docker Toolbox;;.
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\PENGYU~1\AppData\Local\Temp\
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 8.1
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:os.version=6.3
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:user.name=pengyunlong
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\pengyunlong
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Client environment:user.dir=E:\dubbo
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZooKeeper: Initiating client connection, connectString=47.94.102.25:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState@6ba3774f

1.连接zk
[14/06/18 11:18:49:049 CST] main-SendThread(47.94.102.25:2181)  INFO zookeeper.ClientCnxn: Opening socket connection to server 47.94.102.25/47.94.102.25:2181. Will not attempt to authenticate using SASL (unknown error)
[14/06/18 11:18:49:049 CST] main-SendThread(47.94.102.25:2181)  INFO zookeeper.ClientCnxn: Socket connection established to 47.94.102.25/47.94.102.25:2181, initiating session
[14/06/18 11:18:49:049 CST] main-SendThread(47.94.102.25:2181)  INFO zookeeper.ClientCnxn: Session establishment complete on server 47.94.102.25/47.94.102.25:2181, sessionid = 0x163da8bdb61009a, negotiated timeout = 40000
[14/06/18 11:18:49:049 CST] main-EventThread  INFO state.ConnectionStateManager: State change: CONNECTED

2.注册consumer节点
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Register: consumer://192.168.99.2/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=consumers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=consistenthash&methods=sayHello&pid=4536&qos.port=33333&side=consumer&timestamp=1528946328391, dubbo version: 2.0.0, current host: 192.168.99.2

3.订阅providers,configurators,routers等节点数据
[14/06/18 11:18:49:049 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Subscribe: consumer://192.168.99.2/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=consistenthash&methods=sayHello&pid=4536&qos.port=33333&side=consumer&timestamp=1528946328391, dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:18:50:050 CST] main  INFO zookeeper.ZookeeperRegistry:  [DUBBO] Notify urls for subscribe url consumer://192.168.99.2/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=providers,configurators,routers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=consistenthash&methods=sayHello&pid=4536&qos.port=33333&side=consumer&timestamp=1528946328391, urls: [dubbo://192.168.99.2:20881/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=wliliam&pid=7372&side=provider&threadpool=cached&threads=5&timestamp=1528946210558, override://192.168.0.1/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&weight=6, override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&mock=fail%3Areturn+null, override://0.0.0.0/com.alibaba.dubbo.demo.DemoService?category=configurators&dynamic=false&enabled=true&loadbalance=random, empty://192.168.99.2/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=routers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=consistenthash&methods=sayHello&pid=4536&qos.port=33333&side=consumer&timestamp=1528946328391], dubbo version: 2.0.0, current host: 192.168.99.2
[14/06/18 11:18:50:050 CST] main  INFO transport.AbstractClient:  [DUBBO] Successed connect to server /192.168.99.2:20881 from NettyClient 192.168.99.2 using dubbo version 2.0.0, channel is NettyChannel [channel=[id: 0xb6fcd860, /192.168.99.2:56716 => /192.168.99.2:20881]], dubbo version: 2.0.0, current host: 192.168.99.2

4.启动Netty
[14/06/18 11:18:50:050 CST] main  INFO transport.AbstractClient:  [DUBBO] Start NettyClient DESKTOP-DM62SEC/192.168.99.2 connect to the server /192.168.99.2:20881, dubbo version: 2.0.0, current host: 192.168.99.2

5.生成provider的代理
[14/06/18 11:18:50:050 CST] main  INFO config.AbstractConfig:  [DUBBO] Refer dubbo service com.alibaba.dubbo.demo.DemoService from url zookeeper://47.94.102.25:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demo-consumer&check=false&dispatcher=execution&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=random&methods=sayHello&mock=fail%3Areturn+null&owner=wliliam&pid=4536&qos.port=33333&register.ip=192.168.99.2&remote.timestamp=1528946210558&side=consumer&timestamp=1528946328391, dubbo version: 2.0.0, current host: 192.168.99.2

Registry数据节点

zk数据节点

Dubbo启动过程分析

  • 结合dubbo的架构图和dubbo启动日志可以分析出dubbo的启动流程


    dubbo启动流程
  • Provider
    作用:暴露服务的服务提供方
    分析:Provider 启动时会使用Netty监听服务暴露的端口并对外提供服务,然后在Registry的providers节点下注册一个provider临时节点,并且订阅动态配置节点configurators。当configurators发生改变Registry会及时通知provider 。provider是临时节点,所以当Provider和Registry之间的通信出现问题的时候,provider节点会自动删除,此时所有订阅它的节点(consumer等)都会收到通知;

  • Consumer
    作用:调用远程服务的服务消费方
    分析:Consumer启动时也会在Registry中的consumers节点下注册一个consumer临时节点,然后订阅providers\configurators \routers等节点的数据,当providers\configurators \routers数据变化的时候Registry会及时通知consumer。Consumer从Registry拿到Provider地址等信息之后会与Provider 建立长连接,并进行数据通信。由于它订阅了providers节点所以当某个Provider下线的时候,Consumer会收到通知并更新本地的缓存;

  • Registry
    作用:服务注册与发现的注册中心
    分析:Registry一般使用zookeeper、redis等,使用它们的发布与订阅功能来实现服务的注册、下线、配置变更等通知;

  • Monitor
    分析:统计服务的调用次数和调用时间的监控中心,接收Consumer,Provider的统计数据;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349