下图是dubbo的一个整体架构,其中包含了Registry,Consumer,Provider,Monitor等角色。但是可能我们都有一些疑问,比如:这么多角色每个角色的作用是什么?他们是怎么联系起来形成一个整体,如何它们之间是怎么交互的?
下面我们可以通过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×tamp=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×tamp=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®istry=zookeeper×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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®ister.ip=192.168.99.2&remote.timestamp=1528946210558&side=consumer×tamp=1528946328391, dubbo version: 2.0.0, current host: 192.168.99.2
Registry数据节点
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的统计数据;