一.总共分为三个目录:

  • 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. python3中post请求里带list报错

    这个post请求的数据太长,一般data=,json=就够了. 但是今天这个一直报错,用json吧,报缺少参数,用data吧,报多余[. 后来改成data=,并把数据中的[] 用引号括起来," ...

  2. linux动态库加载路径修改

    1.在 /etc/ld.so.conf 文件中添加搜索路径,重启或者 ldconfig 生效: 2.在 /etc/ld.so.conf.d 目录下添加 *.conf 文件,其中可以添加搜索路径,重启获 ...

  3. 洛谷 3398 仓鼠找sugar 【模板】判断树上两链有交

    [题解] 题意就是判断树上两条链是否有交.口诀是“判有交,此链有彼祖”.即其中一条链的端点的Lca在另一条链上. 我们设两条链的端点的Lca中深度较大的为L2,对L2与另一条链的两个端点分别求Lca, ...

  4. 解决maven无法加载本地lib/下的jar包问题(程序包XXX不存在)

    这次一个项目用到maven编译,我在本地开发的时候jar包都是放在WEB-INF/lib目录下,通过 BuildPath将jar包导入,然后用MyEclipse中的:maven package命令打成 ...

  5. Leetcode 132.分割回文串II

    分割回文串 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回符合要求的最少分割次数. 示例: 输入: "aab" 输出: 1 解释: 进行一次分割就可将 s ...

  6. nyoj 5 Binary String Matching(string)

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  7. 【BZOJ2081】Beads(哈希表)

    题意: 翻转是指其中一段长度为k的子串全部翻转 n<=200000 a[i]<=n 思路:枚举k,直接哈希判充即可 时间复杂度是n/i求和,根据定理可得是O(n log n)级别的 单哈双 ...

  8. react实现ssr服务器端渲染总结和案例(实例)

    1.什么是 SSR SSR 是 server side render 的缩写,从字面上就可以理解 在服务器端渲染,那渲染什么呢,很显然渲染现在框架中的前后端分离所创建的虚拟 DOM 2.为什么要实现服 ...

  9. 畅谈HTML开发

    现在,打开浏览器,各种各样的页面可以让人眼花缭乱,对于行外人看到的是美观效果是用户体验,对行内人很多其它的是关注技术和创造力. 对于开发者都知道DIV是一对html经常使用标签,DIV+CSS是一对非 ...

  10. using gdb to debug c program

    #include <stdio.h> static void display(int i, int *ptr); int main(void) { int x = 5; int *xptr ...