dubbo源碼分析 之 架構原理探索

今天我們通過源碼的方式來分析一下Dubbo的架構。

1、準備

在分析探索Dubbo架構原理之前,我們需要準備一下環境,用於後面我們來分析dubbo的架構。

1.1 Zookeeper

Dubbo使用Zookeeper為註冊中心。所以需要在本地啟動zookeeper,作為Dubbo的註冊中心。

  • 啟動Zookeeper服務:用於dubbo的註冊中心。
  • 啟動Zookeeper Inspector:它是Zookeeper服務信息查看工具。
dubbo源碼分析 之 架構原理探索

可以查看zookeeper上面的節點信息。

1.2 Dubbo源代碼

dubbo源代碼的下載地址為:alibaba/dubbo.通過dubbo裡面的dubbo-demo項目我們來分析dubbo的項目架構原理。

1.3 Maven

因為dubbo代碼是通過maven進行項目管理的,所以需要具有maven的知識。

2、Dubbo角色

從服務模型的角度來看,Dubbo採用的是一種非常簡單的模型,要麼是提供方提供服務,要麼是消費方消費服務,所以基於這一點dubbo裡面抽象出了服務提供方(Provider)和服務消費方(Consumer)兩個角色。而連接Provider和Consumer的就是註冊中心(Registry),Provider把服務暴露在Registry上,而Consumer通過Registry來調用暴露在Registry上面的服務。

節點角色說明:

  • Provider: 暴露服務的服務提供方
  • Consumer: 調用遠程服務的服務消費方。
  • Registry: 服務註冊與發現的註冊中心。
  • Monitor: 統計服務的調用次調和調用時間的監控中心。
  • Container: 服務運行容器。
dubbo源碼分析 之 架構原理探索

3、Dubbo Provider

下面我們就來啟動dubbo-demo項目中子項目目dubbo-demo-provider來監控Dubbo在啟動Provider的時候都做了哪些事。首先我們需要把配置文件修改一下。把註冊中心替換成Zookeeper.

>dubbo\dubbo-demo\dubbo-demo-provider\src\test\resources\dubbo.properties

dubbo.container=log4j,springdubbo.application.name=demo-providerdubbo.application.owner=william#dubbo.registry.address=multicast://224.5.6.7:1234dubbo.registry.address=zookeeper://127.0.0.1:2181#dubbo.registry.address=redis://127.0.0.1:6379#dubbo.registry.address=dubbo://127.0.0.1:9090dubbo.monitor.protocol=registrydubbo.protocol.name=dubbodubbo.protocol.port=20880dubbo.service.loadbalance=roundrobin#dubbo.log4j.file=logs/dubbo-demo-consumer.log#dubbo.log4j.level=WARN

然後使用demo裡面的項目來啟動Provider。啟動類為:com.alibaba.dubbo.demo.provider.DemoProvider,它是以main方法啟動。

public class DemoProvider { public static void main(String[] args) { com.alibaba.dubbo.container.Main.main(args); }}

我們首先來觀察一下dubbo Provider的啟動目錄。

Connected to the target VM, address: '127.0.0.1:55696', transport: 'socket'[09/09/17 07:53:33:033 CST] main INFO logger.LoggerFactory: using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter[09/09/17 07:53:33:033 CST] main INFO container.Main: [DUBBO] Use container type([log4j, spring]) to run dubbo serivce., dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:33:033 CST] main INFO container.Main: [DUBBO] Dubbo Log4jContainer started!, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:33:033 CST] main INFO support.ClassPathXmlApplicationContext: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6483f5ae: startup date [Sat Sep 09 19:53:33 CST 2017]; root of context hierarchy[09/09/17 07:53:34:034 CST] main INFO xml.XmlBeanDefinitionReader: Loading XML bean definitions from file [E:\Project\github\dubbo\dubbo-demo\dubbo-demo-provider\target\classes\META-INF\spring\dubbo-demo-provider.xml][09/09/17 07:53:34:034 CST] main INFO support.DefaultListableBeanFactory: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@683dbc2c: defining beans [demoService,com.alibaba.dubbo.demo.DemoService]; root of factory hierarchy[09/09/17 07:53:36:036 CST] main INFO config.AbstractConfig: [DUBBO] The service ready on spring started. service: com.alibaba.dubbo.demo.DemoService, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:37:037 CST] main INFO config.AbstractConfig: [DUBBO] Export dubbo service com.alibaba.dubbo.demo.DemoService to local registry, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:37:037 CST] main INFO config.AbstractConfig: [DUBBO] Export dubbo service com.alibaba.dubbo.demo.DemoService to url dubbo://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=7372&side=provider&timestamp=1504958016968, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:37:037 CST] main INFO config.AbstractConfig: [DUBBO] Register dubbo service com.alibaba.dubbo.demo.DemoService url dubbo://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&monitor=dubbo%3A%2F%2F127.0.0.1%3A2181%2Fcom.alibaba.dubbo.registry.RegistryService%3Fapplication%3Ddemo-provider%26dubbo%3D2.0.0%26owner%3Dwilliam%26pid%3D7372%26protocol%3Dregistry%26refer%3Ddubbo%253D2.0.0%2526interface%253Dcom.alibaba.dubbo.monitor.MonitorService%2526pid%253D7372%2526timestamp%253D1504958017518%26registry%3Dzookeeper%26timestamp%3D1504958016859&owner=william&pid=7372&side=provider&timestamp=1504958016968 to registry registry://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-provider&dubbo=2.0.0&owner=william&pid=7372&registry=zookeeper&timestamp=1504958016859, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:39:039 CST] main INFO transport.AbstractServer: [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /169.254.69.197:20880, dubbo version: 2.0.0, current host: 127.0.0.1--------------------------------------start connection zookeeper------------------------------------------[09/09/17 07:53:39:039 CST] ZkClient-EventThread-17-127.0.0.1:2181 INFO zkclient.ZkEventThread: Starting ZkClient event thread.[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.3.3-1073969, built on 02/23/2011 22:27 GMT[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:host.name=carl[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:java.version=1.8.0_141[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:java.home=D:\tool\Java\jdk1.8.0_141\jre[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\Carl\AppData\Local\Temp\[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:java.compiler=[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 10[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:os.version=10.0[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:user.name=Carl[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\Carl[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Client environment:user.dir=E:\Project\github\dubbo[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZooKeeper: Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.I0Itec.zkclient.ZkClient@42f8285e[09/09/17 07:53:48:048 CST] main-SendThread() INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181[09/09/17 07:53:48:048 CST] main-SendThread(127.0.0.1:2181) INFO zookeeper.ClientCnxn: Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session[09/09/17 07:53:48:048 CST] 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 = 0x15e664ff295000c, negotiated timeout = 30000-------------------------------------------dubbo connectioned-------------------------------------[09/09/17 07:53:48:048 CST] main-EventThread INFO zkclient.ZkClient: zookeeper state changed (SyncConnected)-------------------------------------------dubbo register provider----------------------------------[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: dubbo://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=7372&side=provider&timestamp=1504958016968, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: provider://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=7372&side=provider&timestamp=1504958016968, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:48:048 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url provider://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=7372&side=provider&timestamp=1504958016968, urls: [empty://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=7372&side=provider&timestamp=1504958016968], dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:53:48:048 CST] main INFO container.Main: [DUBBO] Dubbo SpringContainer started!, dubbo version: 2.0.0, current host: 127.0.0.1[2017-09-09 19:53:48] Dubbo service server started!

在上面的啟動日誌中,把dubbo主用的功能都標註了出來。然後我們通過zookeeper Inspector再來看一下zookeeper 的變量。

我們可以看到zookeeper裡面多一個dubbo節點。在dubbo節點下是我們發佈的服務:DemoService的全類名。在服務節點下面有configurations節點與providers節點。而在providers節點如下所示:

/dubbo/com.alibaba.dubbo.demo.DemoService/providers/dubbo%3A%2F%2F169.254.69.197%3A20880%2Fcom.alibaba.dubbo.demo.DemoService%3Fanyhost%3Dtrue%26application%3Ddemo-provider%26dubbo%3D2.0.0%26generic%3Dfalse%26interface%3Dcom.alibaba.dubbo.demo.DemoService%26loadbalance%3Droundrobin%26methods%3DsayHello%26owner%3Dwilliam%26pid%3D15284%26side%3Dprovider%26timestamp%3D1504957132315

這正是我們對provider的配置信息。

所以在provider啟動的時候做了以下幾件事:

  • 連接zookeeper註冊中心,用於dubbo的註冊中心
  • 把服務配置信息以url的形式註冊到zookeeper上面
  • 創建了一個configuration節點,用於監聽訂閱admin的對provider的修改

4、Dubbo Consumer

下面我們就來啟動dubbo-demo項目中子項目目dubbo-demo-consumer來監控Dubbo在啟動Consumer的時候都做了哪些事。首先我們需要把配置文件修改一下。把註冊中心替換成Zookeeper.

>dubbo\dubbo-demo\dubbo-demo-consumer\src\test\resources\dubbo.properties

dubbo.container=log4j,springdubbo.application.name=demo-consumerdubbo.application.owner=#dubbo.registry.address=multicast://224.5.6.7:1234dubbo.registry.address=zookeeper://127.0.0.1:2181#dubbo.registry.address=redis://127.0.0.1:6379#dubbo.registry.address=dubbo://127.0.0.1:9090dubbo.monitor.protocol=registry#dubbo.log4j.file=logs/dubbo-demo-consumer.log#dubbo.log4j.level=WARN

然後使用demo裡面的項目來啟動Consumer。啟動類為:com.alibaba.dubbo.demo.consumer.DemoConsumer,它是以main方法啟動。

public class DemoConsumer { public static void main(String[] args) { com.alibaba.dubbo.container.Main.main(args); }}

我們首先來觀察一下dubbo Consumer的啟動目錄。

Connected to the target VM, address: '127.0.0.1:56208', transport: 'socket'[09/09/17 07:58:52:052 CST] main INFO logger.LoggerFactory: using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter[09/09/17 07:58:52:052 CST] main INFO container.Main: [DUBBO] Use container type([log4j, spring]) to run dubbo serivce., dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:58:52:052 CST] main INFO container.Main: [DUBBO] Dubbo Log4jContainer started!, dubbo version: 2.0.0, current host: 127.0.0.1[09/09/17 07:58:52:052 CST] main INFO support.ClassPathXmlApplicationContext: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6483f5ae: startup date [Sat Sep 09 19:58:52 CST 2017]; root of context hierarchy[09/09/17 07:58:52:052 CST] main INFO xml.XmlBeanDefinitionReader: Loading XML bean definitions from file [E:\Project\github\dubbo\dubbo-demo\dubbo-demo-consumer\target\classes\META-INF\spring\dubbo-demo-action.xml][09/09/17 07:58:53:053 CST] main INFO xml.XmlBeanDefinitionReader: Loading XML bean definitions from file [E:\Project\github\dubbo\dubbo-demo\dubbo-demo-consumer\target\classes\META-INF\spring\dubbo-demo-consumer.xml][09/09/17 07:58:53:053 CST] main INFO support.DefaultListableBeanFactory: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3098cf3b: defining beans [com.alibaba.dubbo.demo.consumer.DemoAction#0,demoService]; root of factory hierarchy[09/09/17 07:58:55:055 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Load registry store file C:\Users\Carl\.dubbo\dubbo-registry-127.0.0.1.cache, data: {com.alibaba.dubbo.demo.DemoService=empty://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&category=configurators&check=false&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=5264&side=provider&timestamp=1504958323428}, dubbo version: 2.0.0, current host: 127.0.0.1--------------------------------------start connection zookeeper------------------------------------------[09/09/17 07:58:55:055 CST] ZkClient-EventThread-15-127.0.0.1:2181 INFO zkclient.ZkEventThread: Starting ZkClient event thread.[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.3.3-1073969, built on 02/23/2011 22:27 GMT[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:host.name=carl[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:java.version=1.8.0_141[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:java.home=D:\tool\Java\jdk1.8.0_141\jre[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\Carl\AppData\Local\Temp\[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:java.compiler=[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 10[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:os.version=10.0[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:user.name=Carl[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\Carl[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Client environment:user.dir=E:\Project\github\dubbo[09/09/17 07:59:04:004 CST] main INFO zookeeper.ZooKeeper: Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.I0Itec.zkclient.ZkClient@1bd39d3c[09/09/17 07:59:05:005 CST] main-SendThread() INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181[09/09/17 07:59:05:005 CST] main-SendThread(127.0.0.1:2181) INFO zookeeper.ClientCnxn: Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session[09/09/17 07:59:05:005 CST] 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 = 0x15e664ff295000e, negotiated timeout = 30000-------------------------------------------dubbo connectioned-------------------------------------[09/09/17 07:59:05:005 CST] main-EventThread INFO zkclient.ZkClient: zookeeper state changed (SyncConnected)-------------------------------------------dubbo Register consumer-------------------------------------[09/09/17 07:59:05:005 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: consumer://169.254.69.197/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=consumers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=14604&side=consumer&timestamp=1504958335273, dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:05:005 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: consumer://169.254.69.197/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=providers,configurators,routers&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=14604&side=consumer&timestamp=1504958335273, dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:05:005 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://169.254.69.197/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=providers,configurators,routers&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=14604&side=consumer&timestamp=1504958335273, urls: [dubbo://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&owner=william&pid=5264&side=provider&timestamp=1504958323428, empty://169.254.69.197/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=configurators&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=14604&side=consumer&timestamp=1504958335273, empty://169.254.69.197/com.alibaba.dubbo.demo.DemoService?application=demo-consumer&category=routers&dubbo=2.0.0&interface=com.alibaba.dubbo.demo.DemoService&methods=sayHello&pid=14604&side=consumer&timestamp=1504958335273], dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:05:005 CST] main INFO transport.AbstractClient: [DUBBO] Successed connect to server /169.254.69.197:20880 from NettyClient 169.254.69.197 using dubbo version 2.0.0, channel is NettyChannel [channel=[id: 0x61ce23ac, /169.254.69.197:56252 => /169.254.69.197:20880]], dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:05:005 CST] main INFO transport.AbstractClient: [DUBBO] Start NettyClient carl/169.254.69.197 connect to the server /169.254.69.197:20880, dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:05:005 CST] main INFO config.AbstractConfig: [DUBBO] Refer dubbo service com.alibaba.dubbo.demo.DemoService from url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demo-consumer&check=false&dubbo=2.0.0&generic=false&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&monitor=dubbo%3A%2F%2F127.0.0.1%3A2181%2Fcom.alibaba.dubbo.registry.RegistryService%3Fapplication%3Ddemo-consumer%26dubbo%3D2.0.0%26pid%3D14604%26protocol%3Dregistry%26refer%3Ddubbo%253D2.0.0%2526interface%253Dcom.alibaba.dubbo.monitor.MonitorService%2526pid%253D14604%2526timestamp%253D1504958335528%26registry%3Dzookeeper%26timestamp%3D1504958335433&owner=william&pid=14604&side=consumer&timestamp=1504958335273, dubbo version: 2.0.0, current host: 169.254.69.197-------------------------------------------dubbo Register monitor routers-------------------------------------[09/09/17 07:59:06:006 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Register: consumer://169.254.69.197/com.alibaba.dubbo.monitor.MonitorService?category=consumers&check=false&dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=14604&timestamp=1504958335528, dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:06:006 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Subscribe: consumer://169.254.69.197/com.alibaba.dubbo.monitor.MonitorService?category=providers,configurators,routers&dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=14604&timestamp=1504958335528, dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 07:59:06:006 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url consumer://169.254.69.197/com.alibaba.dubbo.monitor.MonitorService?category=providers,configurators,routers&dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=14604&timestamp=1504958335528, urls: [empty://169.254.69.197/com.alibaba.dubbo.monitor.MonitorService?category=providers&dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=14604&timestamp=1504958335528, empty://169.254.69.197/com.alibaba.dubbo.monitor.MonitorService?category=configurators&dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=14604&timestamp=1504958335528, empty://169.254.69.197/com.alibaba.dubbo.monitor.MonitorService?category=routers&dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=14604&timestamp=1504958335528], dubbo version: 2.0.0, current host: 169.254.69.197[19:59:06] Hello world0, response form provider: 169.254.69.197:20880[09/09/17 07:59:08:008 CST] main INFO container.Main: [DUBBO] Dubbo SpringContainer started!, dubbo version: 2.0.0, current host: 169.254.69.197[2017-09-09 19:59:08] Dubbo service server started![09/09/17 08:31:18:018 CST] DubboServerHandler-169.254.69.197:20880-thread-199 INFO dubbo.DubboProtocol: [DUBBO] disconected from /169.254.69.197:56751,url:dubbo://169.254.69.197:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-provider&channel.readonly.sent=true&codec=dubbo&dubbo=2.0.0&generic=false&heartbeat=60000&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&monitor=dubbo%3A%2F%2F127.0.0.1%3A2181%2Fcom.alibaba.dubbo.registry.RegistryService%3Fapplication%3Ddemo-provider%26dubbo%3D2.0.0%26owner%3Dwilliam%26pid%3D16392%26protocol%3Dregistry%26refer%3Ddubbo%253D2.0.0%2526interface%253Dcom.alibaba.dubbo.monitor.MonitorService%2526pid%253D16392%2526timestamp%253D1504958572777%26registry%3Dzookeeper%26timestamp%3D1504958572167&owner=william&pid=16392&side=provider&timestamp=1504958572254, dubbo version: 2.0.0, current host: 169.254.69.197-------------------------定時發送數據到monitor------------------------[09/09/17 08:32:00:000 CST] DubboMonitorSendTimer-thread-3 INFO dubbo.DubboMonitor: [DUBBO] Send statistics to monitor zookeeper://127.0.0.1:2181/com.alibaba.dubbo.monitor.MonitorService?dubbo=2.0.0&interface=com.alibaba.dubbo.monitor.MonitorService&pid=16392&timestamp=1504958572777, dubbo version: 2.0.0, current host: 169.254.69.197[09/09/17 08:32:00:000 CST] DubboMonitorSendTimer-thread-3 ERROR dubbo.DubboMonitor: [DUBBO] Unexpected error occur at send statistic, cause: Forbid consumer 169.254.69.197 access service com.alibaba.dubbo.monitor.MonitorService from registry 127.0.0.1:2181 use dubbo version 2.0.0, Please check registry access list (whitelist/blacklist)., dubbo version: 2.0.0, current host: 169.254.69.197

在上面的啟動日誌中,把dubbo主用的功能都標註了出來。然後我們通過zookeeper Inspector再來看一下zookeeper 的變化。

consumer%3A%2F%2F169.254.69.197%2Fcom.alibaba.dubbo.demo.DemoService%3Fapplication%3Ddemo-consumer%26category%3Dconsumers%26check%3Dfalse%26dubbo%3D2.0.0%26interface%3Dcom.alibaba.dubbo.demo.DemoService%26methods%3DsayHello%26pid%3D16704%26side%3Dconsumer%26timestamp%3D1504958628702

這個信息就是我們的對於consumer的配置信息。然後還多了一個routers節點。 這個是我們可以配置demo的路由信息。上面還多了一個com.alibaba.dubbo.monitor.MonitorService節點用於監控dubbo。

5、總結

通過上面我們對dubbo Provider/Consumer的啟動日誌以及通過Zookeeper Inspector對zookeeper服務的觀察我們可以得到dubbo下面的架構圖。

dubbo源碼分析 之 架構原理探索

dubbo源碼分析 之 架構原理探索

分享不易,來波關注吧

視頻詳解: 實例分析dubbo接口調用原理

鏈接:https://pan.baidu.com/s/1U1e5QbRtmtU_5WBtFJ8Xng 密碼:9ob2

dubbo源碼分析 之 架構原理探索

dubbo源碼分析 之 架構原理探索


分享到:


相關文章: