周末两天在家准备把dubbo相关知识系统过一下,顺便写个demo以备以后不时之需,什么时候写demo都是先在网上找一下有没有别人总结好的,有的话直接拿过来修改修改就ok了。通过《一个简单的dubbo服务》
这篇文章在github上找到了对应的demo示例,直接clone下来对照着文章看了一遍没问题尝试着启动dubbo服务。
启动provider:
C:Program FilesJavajdk1.8.0_101injava"
......
[27/08/17 10:48:39:039 CST] main INFO zookeeper.ZookeeperRegistry: [DUBBO] Notify urls for subscribe url provider://192.168.1.101:20880/api.PermissionService?anyhost=true&application=demotest-provider&category=configurators&check=false&dubbo=2.4.10&interface=api.PermissionService&methods=getPermissions&organization=dubbox&owner=programmer&pid=7436&side=provider×tamp=1503802117211, urls: [empty://192.168.1.101:20880/api.PermissionService?anyhost=true&application=demotest-provider&category=configurators&check=false&dubbo=2.4.10&interface=api.PermissionService&methods=getPermissions&organization=dubbox&owner=programmer&pid=7436&side=provider×tamp=1503802117211], dubbo version: 2.4.10, current host: 127.0.0.1
[27/08/17 10:48:39:039 CST] main INFO container.Main: [DUBBO] Dubbo SpringContainer started!, dubbo version: 2.4.10, current host: 127.0.0.1
[2017-08-27 10:48:39] Dubbo service server started!
启动consumer:
"C:Program FilesJavajdk1.8.0_101injava"
......
[27/08/17 10:50:58:058 CST] main INFO config.AbstractConfig: [DUBBO] Refer dubbo service api.PermissionService from url zookeeper://localhost:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demotest-consumer&check=false&connected=true&dubbo=2.4.10&inside.invoker.count=1&inside.invokers=dubbo%3A%2F%2F192.168.1.101%3A20880%2Fapi.PermissionService%3Fanyhost%3Dtrue%26application%3Ddemotest-provider%26dubbo%3D2.4.10%26interface%3Dapi.PermissionService%26methods%3DgetPermissions%26organization%3Ddubbox%26owner%3Dprogrammer%26pid%3D7436%26side%3Dprovider%26timestamp%3D1503802117211&interface=api.PermissionService&methods=getPermissions&organization=dubbox&owner=programmer&pid=8096&side=consumer×tamp=1503802256832, dubbo version: 2.4.10, current host: 192.168.1.101
[Permission_0, Permission_1, Permission_2]
[27/08/17 10:50:58:058 CST] DubboShutdownHook INFO config.AbstractConfig: [DUBBO] Run shutdown hook now., dubbo version: 2.4.10, current host: 192.168.1.101
[27/08/17 10:50:58:058 CST] DubboShutdownHook INFO support.AbstractRegistryFactory: [DUBBO] Close all registries [zookeeper://localhost:2181/com.alibaba.dubbo.registry.RegistryService?application=demotest-consumer&dubbo=2.4.10&interface=com.alibaba.dubbo.registry.RegistryService&organization=dubbox&owner=programmer&pid=8096×tamp=1503802256900], dubbo version: 2.4.10, current host: 192.168.1.101
[27/08/17 10:50:58:058 CST] DubboShutdownHook INFO zookeeper.ZookeeperRegistry: [DUBBO] Destroy registry:zookeeper://localhost:2181/com.alibaba.dubbo.registry.RegistryService?application=demotest-consumer&dubbo=2.4.10&interface=com.alibaba.dubbo.registry.RegistryService&organization=dubbox&owner=programmer&pid=8096×tamp=1503802256900, dubbo version: 2.4.10, current host: 192.168.1.101
......
问题来了,在消费完provider端服务后自动关停消费者端服务!
折腾了一番,替换dubbo版本号(2.8.4)后,正常运行了!
......
[27/08/17 10:37:10:010 CST] main INFO config.AbstractConfig: [DUBBO] Refer dubbo service api.PermissionService from url zookeeper://localhost:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demotest-consumer&check=false&dubbo=2.8.4&generic=false&interface=api.PermissionService&methods=getPermissions&organization=dubbox&owner=programmer&pid=11580&side=consumer×tamp=1503801428993, dubbo version: 2.8.4, current host: 192.168.1.101
[Permission_0, Permission_1, Permission_2]
1、为什么要替换原文示例项目pom.xml指定的dubbo版本号?
其实不止是替换掉了dubbo版本号,示例项目中pom.xml中的dubbo框架依赖本身框架里的spring,里面的spring依赖关系混乱,在替换的时候同时把dubbo的版本号由2.8.4替换成了2.4.10,正是由于低版本的框架bug导致问题的产生,改回2.8.4版本后完美运行!完整pom.xml:
<properties>
<org.springframework.version>4.0.3.RELEASE</org.springframework.version>
<alibaba.dubbo.version>2.8.4</alibaba.dubbo.version>
<zkclient.version>0.1</zkclient.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>dubbotest</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- alibaba dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${alibaba.dubbo.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>