Dubbo+Zookeeper 项目搭建

[b]Dubbo是什么:[/b]

分布式服务框架
--高性能和透明化的RPC远程服务调用方案
--SOA服务治理方案

[b]Dubbo解决问题:[/b]

透明化的远程方法调用,就像调用本地方法一样调用远程方法,只需简单配置,没有任何API侵入。
软负载均衡及容错机制,可在内网替代F5等硬件负载均衡器。
服务自动注册与发现,不再需要写死服务提供方地址,注册中心基于接口名查询服务提供者的IP地址,并且能够平滑添加或删除服务提供者。

[b]Maven工程搭建:[/b]

pom文件见附件pom.zip

[b]项目工程结构:[/b]


[img]http://dl2.iteye.com/upload/attachment/0109/3541/3bf0805f-2850-3eb0-a2b9-3b4d4aa92ead.png[/img]


[img]http://dl2.iteye.com/upload/attachment/0109/3539/b9175e7a-5e35-3b98-9752-cde55348da13.png[/img]


[b]applicationContext_dubbo-provider.xml[/b]

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

<!-- ************************************************************************ -->
<!-- 将多个配置文件位置放到列表中 -->

<bean id="propertyResources" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>classpath:/config.properties</value>
</list>
</constructor-arg>
</bean>

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" ref="propertyResources" />
</bean>

<!-- ************************************************************************ -->

<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="dubbo-service-provider" />

<!-- 使用multicast广播注册中心暴露服务地址 -->
<!--
<dubbo:registry address="multicast://224.5.6.7:1234" />
<dubbo:protocol name="dubbo" port="10880" />
-->

<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry id="techtestRegistry" protocol="zookeeper" address="172.16.11.15:2181" />

<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<dubbo:protocol name="rmi" port="1099" />
<dubbo:protocol name="hessian" port="8080" />

<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="cn.ias.agdis.techtest.dubbo.provider.service.UserService"
ref="userService" version="1.0.0" protocol="dubbo,hessian"/>

<!-- 和本地bean一样实现服务 -->
<bean id="userService" class="cn.ias.agdis.techtest.dubbo.provider.service.impl.UserServiceImpl">
<property name="dao" ref="userDao"/>
</bean>


<!-- dao bean -->
<bean id="userDao" class="cn.ias.agdis.techtest.dubbo.provider.dao.impl.UserDaoImpl" />

</beans>


[b]applicationContext_dubbo-consumer.xml[/b]

<?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="dubbo-service-consumer" />

<dubbo:consumer check = "false"/>

<!-- 使用multicast广播注册中心暴露服务地址 -->
<!--
<dubbo:registry address="multicast://224.5.6.7:1234" />
<dubbo:protocol name="dubbo" port="10880" />
-->

<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry protocol="zookeeper" address="172.16.11.15:2181" />

<!-- 声明需要暴露的服务接口 -->
<dubbo:reference id="userServiceRPC" interface="cn.ias.agdis.techtest.dubbo.provider.service.UserService"
version="1.0.0" registry="techtestRegistry"/>


</beans>


[b]web.xml[/b]

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>

<!-- location of spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext_dubbo-provider.xml,classpath:/applicationContext-webservice-producer.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- CXF servlet -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- all our webservices are mapped under this URI pattern -->
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>

</web-app>


[b]工程源码:[/b]

源码文件见附件 mytechtest.zip
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值