一.总共分为三个目录:

  • 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. webpack3 + vue 添加 serviceWorker

    新的vue脚手架已经可以自带pwa了,本文主要针对旧版的webpack. 先装三个插件: $npm i register-service-worker sw-precache-webpack-plug ...

  2. MySQL Connector/Python 接口 (二)

    连接数据库 本文参见这里,示例如何连接MySQL 数据库. import mysql.connector from mysql.connector import errorcode # 连接数据库需要 ...

  3. 洛谷 1472 奶牛家谱 Cow Pedigrees

    [题解] DP题,我们用f[i][j]表示有n个节点.高度小于等于j的二叉树的个数.f[i][j]=sigma(f[t][j-1]*f[i-t-1][j-1]) t是1~i-1范围内的奇数. #inc ...

  4. Apache 流框架 Flink,Spark Streaming,Storm对比分析(2)

    此文已由作者岳猛授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 2.Spark Streaming架构及特性分析 2.1 基本架构 基于是spark core的spark s ...

  5. noip模拟赛 读

    分析:感觉很像是贪心,但是直接贪找不到方法.一个暴力的想法是枚举最小步数,然后看每个指针能够覆盖到的位置,看看能不能覆盖到所有点.这个求最大覆盖就有点贪心的思想,因为给的ai,bi都是递增顺序的,考虑 ...

  6. 神器的方块Magic Squares

    题目背景 在成功地发明了魔方之后,鲁比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 题目描述 我们知道魔板的每一个方格都有一种颜色.这8种颜 ...

  7. java多线程编程核心技术(三)--线程间通信

    1.等待/通知机制 1.wait()方法:使当前执行代码的线程进行等待.wait()方法是Object类的方法,该方法将当前线程放入“预执行队列”中,并在wait()所处的代码行处停止执行.只到被唤起 ...

  8. [kuangbin带你飞]专题五 并查集 A - Wireless Network

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  9. python 类、模块、包的区别

    学习python的时候,碰到了import 和 from xx import xx的问题, 为了弄清楚什么是 module 和package ,这篇文章讲解的不错!! 原文: http://www.c ...

  10. hdu 4587 推断孤立点+割点+ 删除点之后,剩下多少连通分量

    做了非常久...... 题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4587 先枚举删除的第一个点,第二个点就是找割点.没有割点当然也有答案 学到 ...