1、背景:
一、Dubbo服務正常註冊到ZooKeeper
二、客戶端調用Dubbo服務正常
2、緣由:
Dubbo-Admin未配置分組信息
3、解決步驟:
一、
dubbo.properties添加分組信息:
/usr/local/src/tomcat7/webapps/dubbo-admin/WEB-INF
dubbo.registry.group=
/dubbo/mygroup
二、
dubbo-admin.xml添加分組信息:
/usr/local/src/tomcat7/webapps/dubbo-admin/WEB-INF/classes/META-INF/spring
- <dubbo:registry group="${dubbo.registry.group}" address="${dubbo.registry.address}" check="false" file="false" />
三、重啓tomcat
今天從新配置了下dubbo,結果發現管理控制檯上沒有顯示可用的服務,因爲前陣子剛配置的時候是沒有問題的,因而開始逐步排查。html
項目註冊中心用的zookeeper集羣,provider是採用jar包方式啓動的,consumer在tomcat容器內運行,而且consumer已經能夠消費到provider提供的服務了,說明註冊中心已經裏面已經有服務註冊。經過zookeeper客戶端鏈接到zk服務器上,也能夠看到建立的服務節點web
根目錄下有paopao,zookeeper兩個目錄,其中paopao是根據配置中註冊中心registry的group屬性分組標識而建立的,zookeeper是zk默認的節點,paopao下面有兩個已經註冊的服務節點。spring
而後查看dubbo-admin的配置,dubbo的管理控制檯是在單獨的tomcat下運行的,安裝及配置能夠參考http://dubbo.io/Administrator+Guide-zh.htm,找到webapps/ROOT/WEB-INF/dubbo.properties文件,其內容以下:tomcat
- dubbo.registry.address=zookeeper://192.168.199.191:2181?backup=192.168.199.192:2181,192.168.199.193:2181
- dubbo.admin.root.password=Daniel
- dubbo.admin.guest.password=guest
猛地發現registry沒有配置group分組!本身以前在生產者和消費者的配置文件中也沒有顯式指明分組,默認的group就爲dubbo。如今因爲在服務提供的配置文件中對registry顯式指明瞭group分組,所以管理控制檯的配置中若是沒有聲明group與provider、consumer的group一致,那麼就找不到對應的服務。
因而修改dubbo.properties文件,添加註冊中心分組:
- dubbo.registry.group=paopao
滿懷着激動的心情重啓了服務,結果發現管理臺界面仍是沒有找到服務!而後上網查找可是無奈網上dubbo相關的文檔和討論真的太少了,後來經羣裏一個朋友的提醒,查看了${TOMCAT_HOME}/webapps/ROOT/WEB-INF/classes/META-INF/spring下的dubbo-admin.xml文件,dubbo管理控制檯在啓動的時候會加載該xml文件並讀取裏面的配置信息初始化dubbo和zookeeper,dubbo-admin.xml內容以下:
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
-
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="ignoreResourceNotFound" value="true" />
- <property name="locations">
- <list>
- <value>/WEB-INF/dubbo.properties</value>
- <value>file://${user.home}/dubbo.properties</value>
- </list>
- </property>
- </bean>
-
- <dubbo:application name="dubbo-admin" />
-
- <dubbo:registry address="${dubbo.registry.address}" check="false" file="false" />
-
- <dubbo:reference id="registryService" interface="com.alibaba.dubbo.registry.RegistryService" check="false" />
-
- <bean id="configService" class="com.alibaba.dubbo.governance.service.impl.ConfigServiceImpl" />
-
- <bean id="consumerService" class="com.alibaba.dubbo.governance.service.impl.ConsumerServiceImpl" />
-
- <bean id="overrideService" class="com.alibaba.dubbo.governance.service.impl.OverrideServiceImpl" />
-
- <bean id="ownerService" class="com.alibaba.dubbo.governance.service.impl.OwnerServiceImpl" />
-
- <bean id="providerService" class="com.alibaba.dubbo.governance.service.impl.ProviderServiceImpl" />
-
- <bean id="routeService" class="com.alibaba.dubbo.governance.service.impl.RouteServiceImpl" />
-
- <bean id="userService" class="com.alibaba.dubbo.governance.service.impl.UserServiceImpl">
- <property name="rootPassword" value="${dubbo.admin.root.password}" />
- <property name="guestPassword" value="${dubbo.admin.guest.password}" />
- </bean>
-
- <bean id="governanceCache" class="com.alibaba.dubbo.governance.sync.RegistryServerSync" />
-
- </beans>
能夠看到,該文件居然默認是沒有registry的group屬性的,所以只在dubbo.properties中添加分組配置根本不起做用。因而修改dubbo-admin.xml文件中的<dubbo:registry>項爲:
- <dubbo:registry group="${dubbo.registry.group}" address="${dubbo.registry.address}" check="false" file="false" />
保存後重啓tomcat實例,發現已經註冊的服務提供者和消費者信息,一切OK!服務器
下面把provider和consumer的主要配置信息也貼出來供你們參考:app
provider.xml:webapp
-
- <dubbo:application name="paopao-provider" />
-
-
- <dubbo:registry group="paopao" address="zookeeper://192.168.199.191:2181?backup=192.168.199.192:2181,192.168.199.193:2181"/>
-
-
- <dubbo:monitor protocol="registry"/>
-
-
- <dubbo:protocol name="dubbo" port="20880" />
-
-
- <dubbo:annotation package="com.zhilin.paopao.provider.service"/>
consumer.xml:
- <pre name="code" class="html"> <!-- 消費方應用名,用於計算依賴關係,不是匹配條件,不要與提供方同樣 -->
- <dubbo:application name="consumer-of-app" />
-
- <!-- 使用zookeeper註冊中心暴露發現服務地址 -->
- <dubbo:registry group="paopao" address="zookeeper://192.168.199.191:2181?backup=192.168.199.192:2181,192.168.199.193:2181"/>
-
- <!-- 監控中心配置,從註冊中心發現監控中心地址 -->
- <dubbo:monitor protocol="registry"/>
-
- <!-- 生成遠程服務代理 -->
- <dubbo:reference version="1.0.0" id="userService" interface="com.zhilin.paopao.service.UserService" />