dubbo入门

  要找工作了,就得学习很多东西,还得再面试官面前装的很懂一样,所以我必须得把功课做足,自己要使用过dubbo,才能说自己熟悉dubbo,而不仅仅说自己理解其工作原理就ok了,dobbo的分布式服务中心,底层一般使用了zookeeper,作为分布式服务中心,我很早就听说了,之前学习hadoop好像要有介绍过。dubbo和springcloud都是通常意义上的rpc框架,比如有服务注册中心,只是springcloud采用http协议,dobbo基于tcp。

  首先呢,dubbo有点了类似eureka,都是为开发者提供了一个组件(jar),而不像redis或者rabbitmq是一个服务软件。dubbo怎么使用,官网这句话说得很明白了:

Using the Spring configuration to reference a remote service。

  下面通过一个provider和一个consumer,来体会这个过程。官方推荐使用spring Configuration配置远程服务,但是dubbo有一个缺点,就是功能太多,实施起来不方便。

  报错:

  java.lang.IllegalStateException: Failed to check the status of the service com.example.demo.service.GreetingService. No provider available for the service com.example.demo.service.GreetingService from the url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?application=annotation-consumer&default.timeout=3000&dubbo=2.6.2&interface=com.example.demo.service.GreetingService&methods=sayHello&pid=1175&register.ip=172.20.10.3&side=consumer&timestamp=1592128316906 to the consumer 172.20.10.3 use dubbo version 2.6.2

  看以看到,provider是临时节点,会写入Zookeeper中。按照官网配置,就可以跑起来了。然后我们看下dubbo的注册原理,主要的逻辑就在

com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry中。这张图可以快速看到接口的注册和订阅情况。

 

   

参考博客:

http://dubbo.apache.org/en-us/docs/user/configuration/annotation.html

https://www.cnblogs.com/riches/p/11195184.html

原文地址:https://www.cnblogs.com/Robin008/p/10806949.html