Dubbo—— 一个服务既是消费者又是提供者

实现目标

使用dubbo实现每个服务互相远程调用

ssm实现

依赖

在每个服务中添加:

<dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.5.3</version><exclusions><!-- 项目中已有spring,排除掉dubbo中的 --><exclusion><groupId>org.springframework</groupId><artifactId>spring</artifactId></exclusion></exclusions>
</dependency><!-- 此包必须有,否则不会注册到zookeeper上 -->
<dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.6</version>
</dependency><!-- zookeeper客户端,dubbo2.6之前使用zkclient,2.6之后使用apache的curator -->
<dependency><groupId>com.github.sgroschupf</groupId><artifactId>zkclient</artifactId><version>0.1</version>
</dependency>

storage服务

dubbo-consumer.xml:

<?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:aop="http://www.springframework.org/schema/aop"xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 提供方应用信息,用于计算依赖关系 --><dubbo:application name="dubbo-demo01-storage"  /><!-- 使用multicast广播注册中心暴露服务地址 --><dubbo:registry address="zookeeper://127.0.0.1:2181" /><!-- 声明需要暴露的服务接口 check="false" --><dubbo:reference id="userService" interface="com.dubbo.demo01.api.TUserService" check="false"/></beans>

dubbo-provider.xml:

<?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:aop="http://www.springframework.org/schema/aop"xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 用dubbo协议在20880端口暴露服务 --><dubbo:protocol name="dubbo" port="20881" /><!-- 和本地bean一样实现服务 --><bean id="storageService" class="com.dubbo.demo01.service.TStorageServiceImpl" /><!-- 声明需要暴露的服务接口 --><dubbo:service interface="com.dubbo.demo01.api.TStorageService" ref="storageService" /></beans>

在项目中导入以上配置文件(我是在springmvc.xml中导入的):

<import resource="application-mybatis.xml"/>
<import resource="dubbo-consumer.xml"/>
<import resource="dubbo-provider.xml"/>

user服务

同上:

dubbo-consumer.xml:

<?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:aop="http://www.springframework.org/schema/aop"xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 声明需要暴露的服务接口 --><dubbo:reference id="storageService" interface="com.dubbo.demo01.api.TStorageService" check="false"/></beans>

dubbo-provider.xml:

<?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:aop="http://www.springframework.org/schema/aop"xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 提供方应用信息,用于计算依赖关系 --><dubbo:application name="dubbo-demo01-user"  /><!-- 使用multicast广播注册中心暴露服务地址 --><dubbo:registry address="zookeeper://127.0.0.1:2181" /><!-- 用dubbo协议在20880端口暴露服务 --><dubbo:protocol name="dubbo" port="20880" /><!-- 和本地bean一样实现服务 --><bean id="userService" class="com.dubbo.demo01.service.TUserServiceImpl" /></beans>

在项目中导入以上配置文件(我是在springmvc.xml中导入的):

<import resource="application-mybatis.xml"/>
<import resource="dubbo-consumer.xml"/>
<import resource="dubbo-provider.xml"/>

在启动两个服务之前先启动zookeeper服务 和 dubbo的管理界面

参考

dubbo 解决既是消费者又是提供者 Duplicate application configs 的问题

Zookeeper+Dubbo安装与搭建(2)

dubbo安装跟部署

Dubbo—— 一个服务既是消费者又是提供者相关推荐

  1. dubbo 解决既是消费者又是提供者 Duplicate application configs 的问题

    dubbo 解决既是消费者又是提供者 Duplicate application configs 的问题 参考文章: (1)dubbo 解决既是消费者又是提供者 Duplicate applicati ...

  2. Dubbo笔记 ㉘ : 服务自省-消费者

    文章目录 一.前言 二.ReferenceAnnotationBeanPostProcessor#doGetInjectedBean 1. newProxyInstance 2. ReferenceB ...

  3. Dubbo 通信协议 dubbo 协议为什么要消费者比提供者个数多

    dubbo 通信协议 dubbo 协议为什么要消费者比提供者个数多 因 dubbo 协议采用单一长连接,假设网络为千兆网卡(1024Mbit=128MByte), 根据测试经验数据每条连接最多只能压满 ...

  4. 【springcloudalibaba】naocs+dubbo,服务注册后没有提供者,无法注册No provider available from regist

    问题:服务端A(生产者)注册到nacos后重启,客户端B(消费者)调用A的接口提示 No provider available from registry 可能存在的原因: 1.Q:服务没有订阅 A: ...

  5. Dubbo笔记 ㉗ : 服务自省-提供者

    文章目录 一.前言 1. 概念 二.服务自省 1. 相关配置 3.1 dubbo.application.metadata-type 3.2 dubbo.application.register-co ...

  6. dubbo k8s 服务发现_工商银行基于 Dubbo 构建金融微服务架构的实践-服务发现篇

    作者 | 张远征来源|阿里巴巴云原生公众号 导读:Dubbo 作为分布式微服务框架,众多公司在实践中基于 Dubbo 进行分布式系统架构.重启开源后,我们不仅看到 Dubbo 3.0 最新的 Road ...

  7. Dubbo(四) 消费者、提供者工程搭建并使用注解实现远程调用

    在上一章节<Dubbo(三) 消费者.提供者工程搭建并实现远程调用>中我们简单介绍了Dubbo的概念以及使用xml方式实现了一个消费者和提供者工程,本章介绍使用注解方式实现消费者调用服务提 ...

  8. Dubbo(三) 消费者、提供者工程搭建并实现远程调用

    一.Dubbo概述: Apache Dubbo |ˈdʌbəʊ| 是一款高性能.轻量级的开源Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发 ...

  9. dubbo消费者与提供者之间的tcp长连接

    摘要 dubbo消费者同提供者之间的tcp连接是长连接形式,连接由消费方建立随机端口主动向提供者的dubbo端口发起连接请求,一旦连接建立,除非服务停止.网络异常,否则双方不会主动关闭tcp连接.也就 ...

最新文章

  1. 反arp攻击软件_谈谈电子欺骗中的ARP欺骗
  2. Python最抢手、Go最有前途,7000位程序员揭秘2019软件开发现状
  3. js调用python脚本_javascript – 如何从NodeJs调用python脚本
  4. linux java平台,如何下载和安装用于 Linux 平台的 Java
  5. java : NoSuchMethodError: org.codehaus.jackson.JsonNode.asInt()
  6. 禅道报表中关闭bug统计图_如何生成动态统计图,这款BI教你定义炫酷
  7. windows中文件夹打包成Jar包 cmd命令
  8. 《统计学习方法》python代码资料
  9. Linux ftp ldap认证,vsftpd+ldap认证
  10. 信号与系统——四对时域频域对应关系
  11. (转帖)CAP理论(1)
  12. Java面试题 — Java基础
  13. 【redis】内存优化方案
  14. java+mail+authen_javamail实现smtp身份认证
  15. python中round(18.67、-1)_python的round函数怎么用
  16. c语言用循环函数求平方,用C语言程序三种循环语句分别编写程序,求1-100的平方值?...
  17. python画图设置坐标轴为科学记数法_防止matplotlib.pyplot中的科学记数法
  18. windows内核开发学习笔记十八:IRP 处理的标准模式
  19. android和chrome的发展与未来[j].移动通信,基于Android手机app开发与设计 毕业设计 开题报告...
  20. PowerShell_零基础自学课程_1_初识PowerShell

热门文章

  1. 计算机无法访问苹果相册,iPhone与电脑连接后找不到照片怎么办?掌握这三个技巧,烦恼问题轻松解决!...
  2. MATLAB中:冒号用法
  3. CRM系统概念与项目开发流程
  4. 解决报错Connection terminated as request was larger than 10485760
  5. linux 打开三维stl文件,三维stl文件查看工具下载
  6. 一根网线实现电脑远程登录树莓派
  7. openoffice将word转pdf中文乱码或消失的坑
  8. 从崩溃的系统中恢复多可文档管理系统的办法
  9. echarts地图设置区块点击后颜色不改变
  10. arm搭建云手机教程_全球首个ARM云手机解决方案 基于ARM架构华为云云手机开启公测...