ssm中Dubbo實踐

步驟一:pom.xml引入zk和dubbo

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.5.8</version>
    </dependency>
    <dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
        <version>3.4.11</version>
    </dependency>

步驟二:服務提供方配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
   xmlns="http://www.springframework.org/schema/beans"
   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:provider delay="-1" timeout="10000" retries="0" threadpool="fixed" threads="500" accepts="1000" />

<!-- 服務方應用名,用於計算依賴關係 -->
<dubbo:application name="provider-of-myserver" />

< !-- 使用zookeeper註冊中心來暴露服務地址 --> 
<dubbo:registry  address="zookeeper://192.168.1.163:2181"/>

<!-- 暴露服務 -->  
<dubbo:protocol name="dubbo" port="20880" /> 

<!--聲明需要暴露的服務接口 -->
<dubbo:service version="1.0.0"
               interface="com.zhangna.QueryDataService"
               ref="queryDataService"
               timeout="10000"/>
               
<!-- 實現類 -->  
<bean id="queryDataService" class="com.zhangna.QueryDataService.QueryDataSerivceImpl"></bean>
</beans>

步驟二: 消費方配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
   xmlns="http://www.springframework.org/schema/beans"
   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="consumer-of-mycumser" />

<!-- 使用zookeeper註冊中心暴露服務地址 -
<dubbo:registry  address="zookeeper://192.168.1.163:2181"/>

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

<dubbo:reference interface="com.zhangna.QueryDataService"
                 timeout="10000"
                 id="queryDataService"
                 retries="0"
                 check="false"
                 version="1.0.0"/>

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