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节点,表示同一服务,在注册中心存在多个版本的时候,经过此信息能够区分。 性能