Dubbo zookeeper 初探【轉】

先把zookeeper在本地給安裝好,

這裏的話講述了兩個工程一個工程是提供服務的,一個工程是調用服務的,因爲dubbo是跟spring進行無縫連接的,故功能配置在spring的配置文件中,跟spring進行整合開發

1、工程是以maven進行構建的,使用的jar包如下:


2、服務提供者的工程

a、dubbo-demo-api  定義接口

[java] view plain copy

  1. public interface IProcessData {  

  2.     public String deal(String data);  

  3. }  

b、dubbo-demo-provider 服務提供者



[java] view plain copy

  1. public class ProcessDataImpl implements IProcessData {  

  2.   

  3.     /*  

  4.      * @see com.xxx.bubbo.provider.IProcessData#deal(java.lang.String) 

  5.      */  

  6.     @Override  

  7.     public String deal(String data) {  

  8.         try {  

  9.             Thread.sleep(1000);  

  10.         } catch (InterruptedException e) {  

  11.             e.printStackTrace();  

  12.         }  

  13.         return "Finished:" + data;  

  14.     }  

  15. }  


c、applicationProvider.xml配置



[html] view plain copy

  1. <?xml version="1.0" encoding="UTF-8"?>    

  2. <beans xmlns="http://www.springframework.org/schema/beans"    

  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    

  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans    

  5.         http://www.springframework.org/schema/beans/spring-beans.xsd    

  6.         http://code.alibabatech.com/schema/dubbo    

  7.         http://code.alibabatech.com/schema/dubbo/dubbo.xsd    

  8.         ">    

  9.     

  10.     <!-- Application name -->    

  11.     <dubbo:application name="hello-world-app" />    

  12.     

  13.     <!-- registry address, used for service to register itself -->    

  14.     <dubbo:registry address="zookeeper://127.0.0.1:2181" />    

  15.     

  16.     <!-- expose this service through dubbo protocol, through port 20880 -->    

  17.     <!--    

  18.     <dubbo:protocol name="dubbo" port="20880" />    

  19.         

  20.     <dubbo:protocol name="dubbo" port="9090" server="netty"    

  21.         client="netty" codec="dubbo" serialization="hessian2" charset="UTF-8"    

  22.         threadpool="fixed" threads="100" queues="0" iothreads="9" buffer="8192"    

  23.         accepts="1000" payload="8388608" />    

  24.         -->    

  25.     <!-- Service interface   Concurrent Control  -->    

  26.     <dubbo:service interface="com.huangjie.dubbo_Service.service.IProcessData"    

  27.         ref="demoService" executes="10" />    

  28.     

  29.     <!-- Default Protocol -->    

  30.     <!--   

  31.     <dubbo:protocol server="netty" />   

  32.     -->    

  33.     

  34.     <!-- designate implementation -->    

  35.     <bean id="demoService" class="com.huangjie.dubbo_Service.service.impl.ProcessDataImpl" />    

  36.     

  37. </beans>   


d、啓動服務



[java] view plain copy

  1. public class DubboProviderMain {    

  2.     public static void main(String[] args) throws Exception {    

  3.         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(    

  4.                 new String[]{"applicationProvider.xml"});    

  5.         context.start();  

  6.     

  7.         System.out.println("Press any key to exit.");    

  8.         System.in.read();    

  9.     }    

  10. }   


3、服務調用者的工程


a、調用類


[java] view plain copy

  1. public class ConsumerThd implements Runnable {    

  2.     

  3.     /*   

  4.      * @see java.lang.Runnable#run()  

  5.      */    

  6.     @Override    

  7.     public void run() {  

  8.         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(    

  9.                 new String[]{"applicationConsumer.xml"});    

  10.         context.start();    

  11.     

  12.         IProcessData demoService = (IProcessData) context.getBean("demoService"); // get    

  13.                                                                                 // service    

  14.                                                                                 // invocation    

  15.         // proxy    

  16.         String hello = demoService.deal("nihao"); // do invoke!    

  17.     

  18.         System.out.println(Thread.currentThread().getName() + " "+hello);    

  19.     }    

  20.       

  21.     public static void main(String[] args) {  

  22.         new Thread(new ConsumerThd()).start();  

  23.         /** 

  24.          * 輸出結果: 

  25.          * Thread-0 Finished:nihao 

  26.          */  

  27.     }  

  28. }   


b、applicationConsumer.xml配置



[html] view plain copy

  1. <?xml version="1.0" encoding="UTF-8"?>    

  2. <beans xmlns="http://www.springframework.org/schema/beans"    

  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    

  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans    

  5.         http://www.springframework.org/schema/beans/spring-beans.xsd    

  6.         http://code.alibabatech.com/schema/dubbo    

  7.         http://code.alibabatech.com/schema/dubbo/dubbo.xsd    

  8.         ">    

  9.     

  10.     <!-- consumer application name -->    

  11.     <dubbo:application name="consumer-of-helloworld-app" />    

  12.     

  13.     <!-- registry address, used for consumer to discover services -->    

  14.     <dubbo:registry address="zookeeper://127.0.0.1:2181" />    

  15.     <dubbo:consumer timeout="5000"/>    

  16.     <!-- which service to consume? -->    

  17.     <dubbo:reference id="demoService" interface="com.huangjie.dubbo_Service.service.IProcessData" />    

  18. </beans>   

4、最後需要把zookeeper的服務給啓動,在zookeeper安裝文件夾下面的bin目錄裏面的zkServer.cmd給點擊運行。不要關閉窗口,保持服務運行



這樣整個調用就完成了,這樣的好處是隻要遠程提供ip地址及端口號,以及對外調用的類,客戶端就可以調用,客戶端不必知道服務端的地址之類的

而且服務端可以開多個zookeeper服務,這樣如果其中一個zookeeper 服務死掉了,其他服務還能正常運行

框架/平臺構成:
Maven+Springmvc + Mybatis + Shiro(權限)+ Tiles(模板) +ActiveMQ(消息隊列) + Rest(服務) + WebService(服務)+ EHcache(緩存) + Quartz(定時調度)+ Html5(支持PC、IOS、Android)

用戶權限系統:
組織結構:角色、用戶、用戶組、組織機構;權限點:頁面、方法、按鈕、數據權限、分級授權

項目管理新體驗
快速出原型系統、組件樹、版本控制、模塊移植、協同開發、實時監控、發佈管理

可持續集成:
所有組件可移植、可定製、可擴充,開發成果不斷積累,形成可持續發展的良性循環

支持平臺平臺: 
Windows XP、Windows 7 、Windows 10 、 Linux 、 Unix

服務器容器:
Tomcat 5/6/7 、Jetty、JBoss、WebSphere 8.5 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客

 

JEESZ通用版本分佈式模塊化開發平臺 - zookeeperflume - zookeeperflume的博客


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章