码迷,mamicode.com
首页 > 其他好文 > 详细

Dubbo集成步骤

时间:2014-12-22 14:13:52      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

dubbo协议实现与webservice一样的效果,用于服务调用之间的接口。dubbo可在中间实现真正意义上的中间调用管理,是一个中间管理系统。

demo:http://www.devnote.cn/download/182

同步服务端集成

  同步服务端统一试用dubbo服务端集成到业务系统。目前的场景试用的是dubbo协议。

  1、加入dubbo jar包(附件2.4.10-jar.zip)

 技术分享

  2、在spring配置文件中加入dubbo provider配置

<?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"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/aop
              http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://code.alibabatech.com/schema/dubbo
              http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
              
    <!-- 省略无关配置 -->
    
    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="dubbo-app" />
    <!-- 使用zookeeper注册中心暴露服务地址 -->
    <dubbo:registry address="zookeeper://IP:PORT"
        check="false" />
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.dubbo.provider.service.DubboService"
        ref="dubboService" protocol="dubbo" retries="0" timeout="100000" />
    <!-- 和本地bean一样实现服务 -->
    <bean id="dubboService" class="com.dubbo.provider.service.impl.DubboServiceImpl" />
</beans>

  <dubbo:application/> :应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
  <dubbo:service/> :服务配置,用于暴露一个服务,定义服务的元信息,一个服务可以用多个协议暴露,一个服务也可以注   册到多个注册中心。
  <dubbo:protocol/> :协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
  <dubbo:registry/> :注册中心配置,用于配置连接注册中心相关信息。

  3、把相应的外部接口和所用到的bean(bean或bean的基类要实例化)打成一个jar包


 

同步客户端集成

 1、客户端也许加入相应的dubbojar(2.4.10-jar.zip)

 2、加入dubbo client配置

<?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-custom-app" />
    <!-- 使用zookeeper注册中心暴露发现服务地址 -->
    <dubbo:registry address="zookeeper://IP:PORT"
        check="false" />
    <dubbo:monitor protocol="registry" />
    <dubbo:protocol name="dubbo" port="20880" />
    <!-- 生成远程服务代理,可以和本地bean一样使用dubboService -->
    <dubbo:reference id="dubboService"
        interface="com.dubbo.provider.service.DubboService" protocol="dubbo"
        retries="0" timeout="10000" check="false">
        <!--<dubbo:method name="insertOrUpdateCustomer" async="true" /> -->
    </dubbo:reference>
</beans>

  <dubbo:reference/>  引用配置,用于创建一个远程服务代理,一个引用可以指向多个注册中心。

  3、引入服务方提供的接口和bean打的jar包


 服务方实现读写分离

  若服务方要实现读写分离,可参考如下方案:

  服务端的配置

<!-- 声明需要暴露的服务接口 -->
<!--读服务配置 -->
<dubbo:service group="editDevnoteByClient"
  interface="com.devnote.webService.server.TestService" ref="TestService"
  protocol="dubbo" retries="0" timeout="100000" />

<!--写服务配置 -->
<dubbo:service group="queryDevnoteByClient"
  interface="com.devnote.webService.server.TestService" ref="TestService"
  protocol="dubbo" retries="0" timeout="100000" />

<!-- 和本地bean一样实现服务 -->
<bean id="TestService" class="com.devnote.webService.server.TestServiceImpl" />

   客户端的配置

<!-- 生成远程服务代理,可以和本地bean一样使用dubboService -->
<!--读服务配置 -->
<dubbo:reference id="testServiceEdit" group="editDevNoteByClient"
    listener="" interface="com.devnote.webService.server.TestService"
    protocol="dubbo" retries="0" timeout="10000" check="false">
</dubbo:reference>

<!--写服务配置 -->
<dubbo:reference id="testServiceReader" group="queryDevNoteByClient"
    interface="com.devnote.webService.server.TestService" protocol="dubbo"
    retries="0" timeout="10000" check="false">
</dubbo:reference>

 


  注意点:

  1. 服务端与客户端配置的【zookeeper注册中心暴露服务地址】是由dubbo服务方提供
    <dubbo:registry address="zookeeper://IP:PORT" check="false"/>
  2. 用dubbo协议在20880端口暴露服务

    name:应用方自己暴露在dubbo方的服务名称
    port:类似于自己的tomcat端口,当你的系统有多个服务并分别有应用dubbo时,每个服务都要设置不一样                      的端口,否则会系统会报端口冲突错误

    <dubbo:protocol name="dubbo" port="20880" />
  3. 服务端与客户端通过接口来识别调用
    <dubbo:service interface="com.dubbo.provider.service.DubboService"
        ref="dubboService" protocol="dubbo" retries="0" timeout="100000" />
  4. 如果服务方要实现读写分离则是通过group和接口两个来识别调用
    <dubbo:service group="editDubboByClient"
        interface="com.devnote.webService.server.DubboService" ref="TestService"
        protocol="dubbo" retries="0" timeout="100000" />

Dubbo集成步骤

标签:

原文地址:http://www.cnblogs.com/xmzzp/p/4178055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!