阿里巴巴Dubbo搭建

Dubbo通过高性能的 RPC 实现服务的输出和输入功能,可以和Spring框架无缝集成。

在开始配置之前,需要安装Zookeeper。我使用的是Zookeeper作为注册服务协议。

1. 主要的基础的Maven依赖

<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>



2. 发布服务配置

<?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>



3. 客户端调用服务配置

<?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>



4. 系统结构



如此,实现了简单的Dubbo服务注册及客户端调用。

备注:version节点,表示同一服务,在注册中心存在多个版本的时候,通过此信息可以区分。

转载于:https://my.oschina.net/u/161336/blog/309789

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值