美文网首页
分布式配置dubbo的流程

分布式配置dubbo的流程

作者: 09c72470861c | 来源:发表于2018-09-10 00:53 被阅读0次

每次框架的配置文件几乎都是那之前的项目复制粘贴,修修改改就用起来了。
这样几乎很少从头手写的东西,就要多回顾下。

后面附上配置的代码

dubbo配置流程:

一、pom中依赖dubbo||zookeeper相关jar

二、生产者端:

1.写接口和实现类
2.配置定义提供方应用信息
3.配置zookeeper注册中心
4.用dubbo协议在端口上暴露服务
5.配置接口信息
6.配置实现类信息

三、消费者端

1.配置定义消费这应用信息
2.配置zookeeper的注册地址,以供消费者调接口
3.配置要调用的生产者端的方法

四、打开zookeeper服务器


代码

关于接口的配置那块,删除了很多重复的配置代码,主要注意对应关系就行了

生产者端

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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://www.springframework.org/schema/context
                         http://www.springframework.org/schema/context/spring-context.xsd
                         http://www.springframework.org/schema/aop
                         http://www.springframework.org/schema/aop/spring-aop.xsd
                         http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd
                         http://code.alibabatech.com/schema/dubbo 
                         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">


    <context:component-scan base-package="com.bfy.service" />
    <mvc:annotation-driven />
 
    <!-- dubbo -->

    <!--定义了提供方应用信息,用于计算依赖关系;在 dubbo-admin 或 dubbo-monitor 会显示这个名字,方便辨识 -->
    <dubbo:application name="BFY-manager-service" owner="programmer" organization="dubbox" />
    <!--使用 zookeeper 注册中心暴露服务,注意要先开启 zookeeper -->
    <dubbo:registry address="zookeeper://localhost:2181" />
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />
    <!-- <dubbo:annotation package="com.bfy.service"/> -->
    <!--使用 dubbo 协议实现定义好的 api.PermissionService 接口 -->

    <!-- Service -->

    <dubbo:service  interface="com.bfy.service.PublishMessageService"
        ref="publishMessageService" protocol="dubbo" executes="12000000"
        retries="0" />
    
    <!--具体实现该接口的 bean -->
    <bean id="publishMessageService"
        class="com.bfy.service.impl.PublishMessageServiceImpl" />
    

消费者端

<?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:context="http://www.springframework.org/schema/context"
       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
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">    
    
    <dubbo:application name="demotest-consumer" owner="programmer" organization="dubbox"/>
    <!--向 zookeeper 订阅 provider 的地址,由 zookeeper 定时推送-->
    <dubbo:registry address="zookeeper://localhost:2181"/>
    <!--使用 dubbo 协议调用定义好的 api.PermissionService 接口-->
    <dubbo:reference id="publishMessageService" 
       interface="com.bfy.service.PublishMessageService" 
       retries="0" timeout="1200000"/>    

</beans>

相关文章

  • Dubbo和Zookeeper简介

    Dubbo流程图 Zookeeper是一个高效的分布式协调服务,可以提供配置信息管理、命名、分布式同步、集群管理、...

  • 分布式配置dubbo的流程

    每次框架的配置文件几乎都是那之前的项目复制粘贴,修修改改就用起来了。这样几乎很少从头手写的东西,就要多回顾下。 后...

  • Dubbo

    Dubbo简介 Dubbo是Alibaba提供的一款分布式服务治理框架。其中主要的流程如下 动态代理:生成需要调用...

  • <> 旧版配置文件解析

    实例代码 引入dubbo 依赖 服务 xml 配置 启动类 流程梳理 解析配置文件到 beanDefinitionMap

  • Dubbo高级应用事件之集群容错

    目录: 什么是容错 Dubbo容错模式 Dubbo集群模式配置 什么是容错? 在分布式架构的网络通信中,容错能力是...

  • spring security oauth2.0学习

    认证流程 授权流程 分布式下认证 统一认证授权 统一认证配置 客户端配置,tokenserver端配置,令牌端安全...

  • soul网关学习7-dubbo协议转换2

    继续dubbo协议转换未完成的流程分析。 三、soul-bootstrap端接收配置同步的处理 pom文件引入配置...

  • Dubbo原理和源码解析之标签解析

    一、Dubbo 配置方式 Dubbo 支持多种配置方式: XML 配置:基于 Spring 的 Schema 和 ...

  • Dubbo自定义标签和扩展点

    Alibaba Dubbo是开源的分布式服务治理框架,提供了服务注册,服务发现,动态配置和路由的功能。 Spri...

  • JAVA-每日一面 2022-02-10

    分析一下分布式框架dubbo的好处,不⽤dubbo可不可以。为什么要使⽤分布式1、dubbo好处:1、远程通讯: ...

网友评论

      本文标题:分布式配置dubbo的流程

      本文链接:https://www.haomeiwen.com/subject/cvdjgftx.html