通过dubbo暴露接口调用方法,及基于zookeeper的dubbo涉及配置文件

现在很流行的Dubbo很多朋友都听说过吧,最近我也在看这方面的东西,分享先我的心得笔记。

先说说我们团队要做的项目框架,很简单重在实现基于zookeeper的dubbo注册。

框架:springmvc+spring+mybatis+shiro+zookeeper+dubbo

项目分三层,model存放数据,view页面展示、controller下面具体逻辑实现。通过dubbo消费方和供应方注册,供应方给消费方暴露接口,供消费方调用。 
工程部署需要配置文件有:

 

spring-provider-dubbo.xml(提供方配置文件)

 

<span style="font-size:14px;"><?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 服务提供者应用名称 -->
  <dubbo:application name="demo-dubbo-provider-app" />
  <!--dubbo 注册中心-->
  <dubbo:registry address="zookeeper://192.168.1.125:2181" />
  <!--服务提供者 端口-->
  <dubbo:protocol name="dubbo" port="30001" />
  <!--dubbo提供服务-->
  <dubbo:service interface="com.swrac.www.testdubbo.IGoodsManager" ref="goodsService" />
  <!--spring bean 对象-->
  <bean id="goodsService" class="com.swrac.www.testdubbo.impl.GoodsManager" /> 
</beans></span>

 

spring-consumer-dubbo.xml(消费方配置文件)
{-- 
<-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 --> 

<-- 使用zookeeper注册中心暴露服务地址 --> 

<-- 生成远程服务代理,可以像使用本地bean一样使用demoService --> 
<dubbo:reference id="demoService" interface="com.unj.dubbotest.provider.DemoService" /> 
--}

例如我的配置:

 

<span style="font-size:14px;"><?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="demo-dubbo-consumer-app" />
   <dubbo:registry address="zookeeper://192.168.1.125:2181" />
	<!-- 和本地bean一样实现服务 -->
	<bean id="goodsService" class="com.swrac.www.testdubbo.impl.GoodsManager" /> 
</beans></span>

 

dubbo.properties 
{-- 
<--基于ZooKeeper的Dubbo注册中心直接部署tomcat,修改WEB-INF下文件--> 
dubbo.registry.address=zookeeper://127.0.0.1:2181 
dubbo.admin.root.password=root 
dubbo.admin.guest.password=guest 
--}

本人的配置如下:

 

<span style="font-size:14px;">dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest</span>

 

zoo_sample.cfg 
{-- 
zookeeper/conf/下,修改zoo_sample.cfg为zoo.cfg,启动bin/下zkServer.cmd 
--}

本人的配置如下:

 

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=D:\\Java\\zookeeper-3.4.5\\data
dataLogDir=D:\\Java\\zookeeper-3.4.5\\log
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
# autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
# autopurge.purgeInterval=1

 

因为引入dubbo,摒弃了原有Web Service项目的wdls暴露,由于项目依赖关系严重,项目使用maven构建,通过Maven pom.xml三维坐标引入jar包,调用dubbo暴露接口开发。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JAIR_FOREVER

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值