zoukankan      html  css  js  c++  java
  • Dubbo集成步骤

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

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

    同步服务端集成

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

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

     Dubbo集成步骤

      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" />
  • 相关阅读:
    apache安全—用户访问控制
    hdu 3232 Crossing Rivers 过河(数学期望)
    HDU 5418 Victor and World (可重复走的TSP问题,状压dp)
    UVA 11020 Efficient Solutions (BST,Splay树)
    UVA 11922 Permutation Transformer (Splay树)
    HYSBZ 1208 宠物收养所 (Splay树)
    HYSBZ 1503 郁闷的出纳员 (Splay树)
    HDU 5416 CRB and Tree (技巧)
    HDU 5414 CRB and String (字符串,模拟)
    HDU 5410 CRB and His Birthday (01背包,完全背包,混合)
  • 原文地址:https://www.cnblogs.com/xmzzp/p/4178055.html
Copyright © 2011-2022 走看看