一.总共分为三个目录:

  • dubbo-api      服务的接口用于对接客户端和服务端 
  • dubbo-client     客户端配置文件为:consumer.xml
  • dubbo-service  服务端配置文件为:provide.xml  

二.配置文件

  1.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: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="consumer" />
<!-- zookeeper作为注册中心 -->
<dubbo:registry protocol="zookeeper"
address="zookeeper://10.92.1.17:2181" />
<dubbo:protocol name="dubbo" port="" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference
interface="com.dubbo.api.rpc.TestService" id="testService"></dubbo:reference>
</beans>

  2.provide.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: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="provider" />
<!-- 使用zookeeper作为注册中心 -->
<dubbo:registry protocol="zookeeper"
address="zookeeper://10.92.1.17:2181" />
<dubbo:protocol name="dubbo" port="" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:service interface="com.dubbo.api.rpc.TestService"
ref="testService"></dubbo:service>
</beans>

  3pom文件:   

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.dubbo.api</groupId>
<artifactId>dubbo-api</artifactId>
<version>0.0.-SNAPSHOT</version>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>

  4. 服务的接口

/**
* @Title: TestService.java
* @Description:
* @author lsc
* @date 2018年8月17日
* @version 1.0
* @Copyright:Copyright Taikanglife.All Rights Reserved
*/
package com.dubbo.api.rpc; /**
* @ClassName: TestService
* @Description:
* @author: lsc
* @date: 2018年8月17日 上午10:03:28
* @Copyright:Copyright Taikanglife.All Rights Reserved
*/
public interface TestService { public String sayHello();
}

  5.服务的实现

package com.dubbo.dubbo;

import org.springframework.stereotype.Service;

import com.dubbo.api.rpc.TestService;

/**
* @ClassName: TestServiceImpl
* @Description:
* @author: lsc
* @date: 2018年8月17日 上午10:24:11
* @Copyright:Copyright Taikanglife.All Rights Reserved
*/
@Service("testService")
public class TestServiceImpl implements TestService {
@Override
public String sayHello() {
return "hello dubbo";
}
}

  6.服务的调用

package com.dubbo.dubboclient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.dubbo.api.rpc.TestService; /**
* @ClassName: MyController
* @Description:
* @author: lsc
* @date: 2018年8月17日 上午10:24:56
* @Copyright:Copyright Taikanglife.All Rights Reserved
*/
@RestController
public class MyController { @Autowired
private TestService testService; @RequestMapping("/home")
public String home(){
return testService.sayHello();
}
}

  

dubbo+zookeeper下生产者和消费者配置(基于springboot开发)的更多相关文章

  1. 基于SpringBoot开发一个Restful服务,实现增删改查功能

    前言 在去年的时候,在各种渠道中略微的了解了SpringBoot,在开发web项目的时候是如何的方便.快捷.但是当时并没有认真的去学习下,毕竟感觉自己在Struts和SpringMVC都用得不太熟练. ...

  2. Kafka学习笔记3--Kafka的生产者和消费者配置

    下载解压 kafka 后,在 kafka/config 下有 3 个配置文件与主题及其生产.消费相关. server.properties--服务端配置 producer.properties--生产 ...

  3. 带着新人学springboot的应用12(springboot+Dubbo+Zookeeper 下)

    上半节已经下载好了Zookeeper,以及新建了两个应用provider和consumer,这一节我们就结合dubbo来测试一下分布式可不可以用. 现在就来简单用一下,注意:这里只是涉及最简单的部分, ...

  4. dubbo中拦截生产者或消费者服务方法调用

    比如当前有个需求,需要拦截dubbo的服务提供方或者服务消费方的方法,判断参数中是否包含某个关键字进行拦截阻止执行,那么我们可以通过使用dubbo的SPI机制通过实现Filter类来拦截,话不多说直接 ...

  5. Linux下生产者与消费者的线程实现

    代码见<现代操作系统> 第3版. 为了显示效果,添加了printf()函数来显示运行效果 #include<stdio.h> #include<pthread.h> ...

  6. TIMO后台管理系统-基于SpringBoot开发

    项目介绍 TIMO后台管理系统,基于SpringBoot2.0 + Spring Data Jpa + Thymeleaf + Shiro 开发的后台管理系统,采用分模块的方式便于开发和维护,支持前后 ...

  7. 重学 Java 设计模式:实战外观模式「基于SpringBoot开发门面模式中间件,统一控制接口白名单场景」

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 你感受到的容易,一定有人为你承担不容易 这句话更像是描述生活的,许许多多的磕磕绊绊总 ...

  8. Dubbo+zookeeper实现单表的增删改查

    1.数据库准备 建表语句 CREATE TABLE `tb_brand` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) DEFAULT NULL COMMENT ...

  9. 通过单元测试理解spring容器以及dubbo+zookeeper单元测试异常处理

    一.先说一个结论:单元测试与主项目的spring容器是隔离的,也就是说,单元测试无法访问主项目spring容器,需要自己加载spring容器. 接下来是代码实例,WEB主项目出于运行状态,单元测试中可 ...

随机推荐

  1. 利用postman进行接口测试并发送带cookie请求的方法

    做web测试的基本上都用用到postman去做一些接口测试,比如测试接口的访问权限,对于某些接口用户A可以访问,用户B不能访问:比如有时需要读取文件的数据.在postman上要实现这样测试,我们就必要 ...

  2. ACM多校联赛7 2018 Multi-University Training Contest 7 1009 Tree

    [题意概述] 给一棵以1为根的树,树上的每个节点有一个ai值,代表它可以传送到自己的ai倍祖先,如果不存在则传送出这棵树.现在询问某个节点传送出这棵树需要多少步. [题解] 其实是把“弹飞绵羊”那道题 ...

  3. [luoguP3052] [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper(DP)

    传送门 输出被阉割了. 只输出最少分的组数即可. f 数组为结构体 f[S].cnt 表示集合 S 最少的分组数 f[S].v 表示集合 S 最少分组数下当前组所用的最少容量 f[S] = min(f ...

  4. word分节时,如何让每一节的首页置为奇数页

    具体操作,可参考如下图片所示的步骤: 打印时的效果: 备注:目录页为第二小节首页(文档的第二页),整个文档的首页为封面第一页. 打印时,会在首页后自动插入一张空白页:也会在正文(第三页,第三节)前,目 ...

  5. mybatis中jdbcType的作用和是否必须

    1. mybatis中 jdbcType 时间类型 当jdbcType = DATE 时, 只传入了 年月日 jdbcType = TIMESTAMP ,  年月日+ 时分秒 2. jdbcType ...

  6. 1. MissingInteger 最小遗失整数 Find the minimal positive integer not occurring in a given sequence.

    package com.code; import java.util.Arrays; public class Test04_1 { public static int solution(int[] ...

  7. 新手学測试----Unit Test(单元測试)

    在程序猿做项目的过程中,每当完毕一个功能,首先自己须要对完毕的功能进行測试.我如今正在做的项目用的工具是VS2012.那么接下来,就说一说在VS2012中是怎样创建单元測试的. 怎样创建单元測试? 在 ...

  8. ROBODK仿真如何设置运动速度

    设置工具-选项-运动,把仿真时间设置成跟正常一样   然后双击机器人,设置参数(可以设置movej和movel的速度,加速度)  

  9. express 不是内部或外部命令(windows)解决方式

    请环境变量设置 注意 "D:\soft\nodejs\"这个是笔者自己安装在电脑上的node js文件夹,请改动成自己的 假设安装的express是4.X就要安装 express- ...

  10. 《天龙八部》及Ogre3D模型的3ds max导入插件(源码公布)

    測试UE4项目.苦于没有像样的模型和动画资源,所以想到把<天龙八部>等网游的资源导出来用. 于是做了个max导入插件. 效果还是不错的. 效果图: 上图是<斗破苍穹>的游戏资源 ...