Dubbo經過高性能的 RPC 實現服務的輸出和輸入功能,能夠和Spring框架無縫集成。 spring
在開始配置以前,須要安裝Zookeeper。我使用的是Zookeeper做爲註冊服務協議。 apache
1. 主要的基礎的Maven依賴
app
<dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <!-- <version>2.0.13</version> --> <version>2.5.3</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.6</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.4</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> </dependencies>
<?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="hello-world-app" /> <!--zookeeper註冊中心 --> <dubbo:registry protocol="zookeeper" address="192.168.10.150:2181" /> <!--使用multicast廣播註冊中心暴露服務地址 --> <!--<dubbo:registry address="multicast://10.57.41.19:1234" /> --> <dubbo:protocol name="dubbo " port="20881" /> <dubbo:service interface="com.yanmushi.dubbo.OpenService" ref="openService" version="1.0" /> <!-- 和本地bean同樣實現服務 --> <bean id="openService" class="com.yanmushi.dubbo.impl.OpenServiceImpl" /> </beans>
<?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="consumer-of-helloworld-app" /> <!--zookeeper註冊中心 --> <dubbo:registry protocol="zookeeper" address="192.168.10.150:2181" /> <!--使用multicast廣播註冊中心暴露的服務地址 --> <!--<dubbo:registryaddress="multicast://10.57.41.19:1234" /> --> <!-- 生成遠程服務代理,能夠和本地bean同樣使用demoService --> <dubbo:reference id="openService" interface="com.yanmushi.dubbo.OpenService" version="1.0" /> </beans>
如此,實現了簡單的Dubbo服務註冊及客戶端調用。 框架
備註:version節點,表示同一服務,在註冊中心存在多個版本的時候,經過此信息能夠區分。 性能