springboot下的dubbo、zookeeper 結合使用

來源:互聯網
上載者:User

標籤:需要   use   add   lib   sum   port   strong   xmla   方式   

近期在研究dubbo架構

相信看到這篇部落格的,dubbo的基礎應該都有了

zookeeper的搭建走了點彎路,配置起來各種麻煩,媽的搞的好煩。

正好一直想用一下docker,但對docker只是有個簡單的概念。

用了一晚上去研究docker,之後發現真的好用

搭建個zookeeper就跟玩似的。

這裡記錄一下遇到的一些坑!

1、springboot引入dubbo的設定檔

網上搜尋了一下,大概的兩種方式

1、 這種方式是通過 ClassPathXmlApplicationContext 載入xml來擷取上下文Context啟動

 1 @SpringBootApplication 2  3 public class WreserveApplication { 4  5     public static void main(String[] args) throws IOException, InterruptedException { 6          ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"dubbo-provider.xml"}); 7          context.start(); 8          System.in.read(); // press any key to exit 9     }10 11 }

2、通過 @ImportResource({ "classpath:dubbo-provider.xml" }) 載入。

 1 @SpringBootApplication 2 @ImportResource({ "classpath:dubbo-provider.xml" }) 3 public class WreserveApplication { 4     @Bean 5     public CountDownLatch closeLatch() { 6         return new CountDownLatch(1); 7     } 8  9     public static void main(String[] args) throws IOException, InterruptedException {10         ConfigurableApplicationContext context = SpringApplication.run(WreserveApplication.class, args);11         CountDownLatch closeLatch = context.getBean(CountDownLatch.class);12         closeLatch.await();13 14     }15 16 }
2、dubbo-provider.xml和dubbo-consumer.xml中需要注意的一些問題

dubbo-provider.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">        <dubbo:application name="demo-provider"/>    <!-- use multicast registry center to export service -->    <dubbo:registry address="zookeeper://192.168.99.100:2181"/>    <!-- use dubbo protocol to export service on port 20880 -->    <dubbo:protocol name="dubbo" port="20880"/>    <!-- service implementation, as same as regular local bean -->    <bean id="helloService" class="com.zhyonk.service.Impl.HelloServiceImpl"/>    <!-- declare the service interface to be exported -->    <dubbo:service interface="com.zhyonk.service.HelloService" ref="helloService"/>    </beans>

dubbo-consumer.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    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://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">    <dubbo:application name="wreserve-wechat"></dubbo:application>    <!--zookeeper註冊中心 -->    <dubbo:registry        address="zookeeper://192.168.99.100:2181"></dubbo:registry>    <dubbo:consumer check="false" timeout="60000" />    <!-- 產生遠程服務代理,可以和本地bean一樣使用demoService -->    <dubbo:reference id="helloService"        interface="com.zhyonk.wreserve.service.HelloService" protocol="dubbo"        timeout="15000" /></beans>

 

1、消費者要訪問提供者,

<dubbo:reference id="helloService"        interface="com.zhyonk.wreserve.service.HelloService" protocol="dubbo"
    <!-- service implementation, as same as regular local bean -->    <bean id="helloService" class="com.zhyonk.service.Impl.HelloServiceImpl"/>    <!-- declare the service interface to be exported -->    <dubbo:service interface="com.zhyonk.service.HelloService" ref="helloService"/>

其中的interface必須要求同一個路徑之下,不然對應不上,會出現下面的情況

正常情況下dubbo-admin中會顯示

2、如果嫌自己搭建麻煩的話可以直接用用網站自動產生 http://start.dubbo.io/

就先到這,睡了

 

springboot下的dubbo、zookeeper 結合使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.