1. 程式人生 > >dubbo 部分 配置的關系-dubbo github 官方案例

dubbo 部分 配置的關系-dubbo github 官方案例

回首 CI http mis 有一個 官網 width alibaba ftw

1、dubbo 有一個 dubbo.properties 作為默認配置

默認配置可以在不添加新的配置的前提下使用dubbo


dubbo.properties 的內容(來自 https://github.com/alibaba/dubbo)


2、dubbo 學習參考鏈接

·dubbo-admin管理控制臺的安裝和使用:http://www.cnblogs.com/aqsunkai/p/6690607.html
·dubbo官網,下載和配置說明:http://dubbo.io/
·dubbo結合Spring:http://blog.csdn.net/congcong68/article/details/41113239
·dubbo 配置 :http://www.cnblogs.com/linjiqin/p/5859153.html
·zookeeper 基本含義: http://blog.csdn.net/gyflyx/article/details/18652913


3、本地環境搭建-zookeeper(windows 環境)

http://blog.csdn.net/bestcxx/article/details/73440892


4、從github下載 dubbo 測試所需的幾個工程

https://github.com/alibaba/dubbo

技術分享圖片

先全部下載,然後取其中的 dubbo-admin和dubbo-demo

dubbo-admin是dubbo監控平臺,可以打包為war或者直接jetty運行(maven 配置 jetty 插件),啟動後訪問 http://localhost:9999/dubbo-admin 端口9999看你怎麽定義了

需要輸入用戶名和密碼:root/root

之後點擊 返回首頁

技術分享圖片

然後進入預期的界面了

技術分享圖片


dubbo-demo聚合了demo-api\demo-consumer\demo-provider

demo-api是接口,demo-proveider 實現了demo-api

demo-provider是提供者

demo-consumer是消費者

demo-provider和demo-consumer 都是在test中提供main方法啟動,demo-consumer 一直調用,可以看到兩個平臺的交互

技術分享圖片


5、實驗得出的結論

dubbo.properties 會起到默認配置的作用

技術分享圖片

但是 dubbo-demo-provider.xml 中的配置可以對dubbo.properties 的配置進行覆蓋和擴展(這意味著某些配置不是必須的)

dubbo-demo-provider.xml 的內容(DemoTwoServiceImpl.java 和 DemoTwoService.java 是新增的兩個類,分別加在dubbo-provider 和 dubbo-api中,參照先例即可)

[html] view plain copy print?
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. - Copyright 1999-2011 Alibaba Group.
  4. -
  5. - Licensed under the Apache License, Version 2.0 (the "License");
  6. - you may not use this file except in compliance with the License.
  7. - You may obtain a copy of the License at
  8. -
  9. - http://www.apache.org/licenses/LICENSE-2.0
  10. -
  11. - Unless required by applicable law or agreed to in writing, software
  12. - distributed under the License is distributed on an "AS IS" BASIS,
  13. - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. - See the License for the specific language governing permissions and
  15. - limitations under the License.
  16. -->
  17. <beans xmlns="http://www.springframework.org/schema/beans"
  18. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  19. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  20. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  21. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
  22. <!-- bean的聲明和Spring無差異 -->
  23. <bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl" />
  24. <bean id="demoTwoService" class="com.alibaba.dubbo.demo.provider.DemoTwoServiceImpl" />
  25. <!-- 由於dubbo.propertirs 的存在,可以直接配置 <dubbo:service>對外暴露服務,即存在默認的配置, -->
  26. <dubbo:service interface="com.alibaba.dubbo.demo.DemoTwoService" ref="demoTwoService" group="dubbodemoregister2"/>
  27. <!-- 如果需要使用個性化配置,則需要單獨配置,比如服務提供者協議配置、註冊中心配置 、服務提供者缺省值配置-->
  28. <!-- 服務提供者協議配置-dubbo會覆蓋dubbo.properties: -->
  29. <!-- <dubbo:protocol id="dubbodemo" name="dubbo" port="20882"/> -->
  30. <!-- 註冊中心配置-會覆蓋 dubbo.proerties,這個本質就是 dubbo:service的group: -->
  31. <dubbo:registry id="dubbodemoregister" address="zookeeper://127.0.0.1:2181" protocol="dubbo"/>
  32. <dubbo:registry id="dubbodemoregister2" address="zookeeper://127.0.0.1:2181" protocol="dubbo"/>
  33. <!-- 服務提供者缺省值配置-所有服務提供者自動擁有此配置-這意味著,這個配置一個就夠了: -->
  34. <!-- <dubbo:provider id="dubbodemoprovider" group="dubbodemoregister" timeout="30000" retries="0"/> -->
  35. <!-- 服務提供者暴露服務配置: -->
  36. <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" group="dubbodemoregister"/>
  37. </beans>






dubbo 部分 配置的關系-dubbo github 官方案例