SpringBoot整合Dubbo+Zookeaper

1.安装运行zookeeper

(1)下载zookeeper

官网:http://zookeeper.apache.org/

(2)解压缩

(3)修改配置文件

  1. 拷贝zoo_sample.cfg重命名为zoo.cfg

  2. 修改配置文档

    # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial
    # synchronization phase can take
    initLimit=10
    # The number of ticks that can pass between
    # sending a request and getting an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just
    # example sakes.
    dataDir=../data
    # the port at which the clients will connect
    clientPort=2181
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60
    #
    # Be sure to read the maintenance section of the
    # administrator guide before turning on autopurge.
    #
    # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    #
    # The number of snapshots to retain in dataDir
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
  3. 创建data文件夹

(4)cmd启动zkServer.sh

2.安装dubbo web管理客户端

(1)下载Duboo OPS

下载地址:https://github.com/apache/incubator-dubbo-ops/tree/master

(2)修改配置

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# server.port=7001
spring.velocity.cache=false
spring.velocity.charset=UTF-8
spring.velocity.layout-url=/templates/default.vm
spring.messages.fallback-to-system-locale=false
spring.messages.basename=i18n/message
spring.root.password=root
spring.guest.password=guest dubbo.registry.address=zookeeper://127.0.0.1:2181

(3)maven打包dubbo-admin

(4)启动生成jar

(5)访问http://localhost:7001/

3.安装dubbo监控服务中心

(1)maven打包dubbo-monitor-simple

(2)解压dubbo-monitor-simple-2.0.0-assembly.tar.gz

(3)修改配置文件

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. dubbo.container=log4j,spring,registry,jetty-monitor
dubbo.application.name=simple-monitor
dubbo.application.owner=dubbo
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://127.0.0.1:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.protocol.port=7070
dubbo.jetty.port=8080
dubbo.jetty.directory=${user.home}/monitor
dubbo.charts.directory=${user.home}/monitor/charts
dubbo.statistics.directory=${user.home}/monitor/statistics
dubbo.log4j.file=logs/dubbo-monitor-simple.log
dubbo.log4j.level=WARN

(4)启动start.bat

(5)访问http://localhost:8080/

4.整合springboot

(1)新建Maven项目:d_api :一个公用service的api

  1. 新建一个接口:HelloService

    package com.xm.dubbo.service;
    
    public interface HelloService {
    
    	String sayHello();
    
    }
    
    

(2)新建Springboot项目:Hello_Producer

参考链接:https://github.com/apache/incubator-dubbo-spring-boot-project

  1. 添加依赖

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion> <groupId>com.xm.dubbo</groupId>
    <artifactId>hello_producer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging> <name>hello_producer</name>
    <description>This is a Web about springcloud</description> <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent> <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    </properties> <dependencies>
    <dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>0.2.0</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    </dependency> <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>com.xm.dubbo</groupId>
    <artifactId>d_api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </dependency>
    </dependencies> <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build> </project>
  2. 修改配置文件

    dubbo.application.name=hello_producer
    dubbo.registry.protocol=zookeeper
    dubbo.registry.address=127.0.0.1:2181
    dubbo.scan.base-packages=com.xm.dubbo.service
    dubbo.protocol.name=dubbo
    dubbo.protocol.port=20080
    dubbo.monitor.protocol=registry
  3. 新建HelloServiceImpl

    package com.xm.dubbo.service.impl;
    
    import org.springframework.stereotype.Component;
    
    import com.alibaba.dubbo.config.annotation.Service;
    import com.xm.dubbo.service.HelloService; @Service
    @Component
    public class HelloServiceImpl implements HelloService { @Override
    public String sayHello() {
    System.out.println("生产者已被调用!");
    return "Hello dubbo!";
    } }
  4. 项目入口添加@EnableDubbo注解

    package com.xm.dubbo;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication; import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; @EnableDubbo
    @SpringBootApplication
    public class HelloProducerApplication { public static void main(String[] args) {
    SpringApplication.run(HelloProducerApplication.class, args);
    }
    }

(3)新建Springboot项目:Hello_Consumer

  1. 添加依赖

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion> <groupId>com.xm.dubbo</groupId>
    <artifactId>hello_consumer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging> <name>hello_consumer</name>
    <description>This is a Web about springcloud</description> <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent> <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    </properties> <dependencies>
    <dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>0.2.0</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency> <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>com.xm.dubbo</groupId>
    <artifactId>d_api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </dependency>
    </dependencies> <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build> </project>
  2. 修改配置文件

    server.port=8081
    
    dubbo.application.name=hello_consumer
    dubbo.registry.protocol=zookeeper
    dubbo.registry.address=127.0.0.1:2181
    dubbo.monitor.protocol=registry
  3. 新建HelloController

    package com.xm.dubbo.controller;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController; import com.alibaba.dubbo.config.annotation.Reference;
    import com.xm.dubbo.service.HelloService; @RestController
    public class HelloController { @Reference
    private HelloService helloService; @GetMapping("/hello")
    public String sayHello() {
    return helloService.sayHello();
    } }
  4. 项目入口添加@EnableDubbo注解

    package com.xm.dubbo;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication; import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; @EnableDubbo
    @SpringBootApplication
    public class HelloConsumerApplication { public static void main(String[] args) {
    SpringApplication.run(HelloConsumerApplication.class, args);
    }
    }

17、SpringBoot------整合dubbo的更多相关文章

  1. Springboot整合Dubbo和Zookeeper

    Dubbo是一款由阿里巴巴开发的远程服务调用框架(RPC),其可以透明化的调用远程服务,就像调用本地服务一样简单.截至目前,Dubbo发布了基于Spring Boot构建的版本,版本号为0.2.0,这 ...

  2. springboot整合dubbo\zookeeper做注册中心

    springboot整合dubbo发布服务,zookeeper做注册中心.前期的安装zookeeper以及启动zookeeper集群就不说了. dubbo-admin-2.5.4.war:dubbo服 ...

  3. 【转】SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)

    http://blog.csdn.net/a67474506/article/details/61640548 Dubbo是什么东西我这里就不详细介绍了,自己可以去谷歌 SpringBoot整合Dub ...

  4. SpringBoot整合dubbo(yml格式配置)

    yml文件 如果只作为服务的消费者不用暴露端口号,扫描的包名根据自己service改 dubbo: application: name: springboot-dubbo-demo #应用名 regi ...

  5. dubbo学习实践(4)之Springboot整合Dubbo及Hystrix服务熔断降级

    1. springboot整合dubbo 在provider端,添加maven引入,修改pom.xml文件 引入springboot,版本:2.3.2.RELEASE,dubbo(org.apache ...

  6. Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例

    摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢!   “看看星空,会觉得自己很渺小,可能我们在宇宙中从来就是一个偶然.所以,无论什么事情,仔细想一 ...

  7. SpringBoot整合dubbo

    Dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和Spring框架无缝集成. 以上介绍来源于百度百科,具体dubbo相关可以自行查 ...

  8. spring-boot整合dubbo启动demo

    参考资料: https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/html/ https://github.com/apach ...

  9. springboot整合dubbo+zookeeper最新详细

    引入 最近和小伙伴做一个比赛,处于开发阶段,因为涉及的服务比较多,且服务需要分开部署在不同的服务器上,讨论之后,打算采用分布式来做,之前学习springboot的时候,部分章节涉及到了springbo ...

  10. springboot整合dubbo的简单案例

    使用框架: jdk 1.8 springboot-2.1.3 dubbo-2.6 spring-data-jpa-2.1.5 一.开发dubbo服务接口: 按照Dubbo官方开发建议,创建一个接口项目 ...

随机推荐

  1. vue router-link 添加在定义事件

    在vue学习中遇到给router-link 标签添加事件@click .@mouseover等无效的情况 我想要做的是v-for遍历出来的选项卡, 鼠标移上去出现删除标签,移除标签消失的效果 原代码: ...

  2. (转)Rsync命令详解

    Rsync命令详解 原文:http://blog.51cto.com/irow10/1826249 说明: Rsync是linux/Unix文件同步和传送工具.用于替代rcp的一个工具,rsync可以 ...

  3. 使用 Charles 获取 https 的数据

    1. 配置 Charles 根证书 首先打开 Charles: 然后如下图操作: 之后会弹出钥匙串,如果不弹出,请自行打开钥匙串,如下图: 系统默认是不信任 Charles 的证书的,此时对证书右键, ...

  4. 牛客网Java刷题知识点之输入流、输出流、字节流、字符流、字节流的抽象基类(InputStream、OutputStream)、字符流的抽象基类(Reader、Writer)、FileWriter、FileReader

    不多说,直接上干货! IO流用来处理设备之间的数据传输. java对数据的操作是通过流的方式. java用于操作流的对象都在IO包中. IO流按操作数据分为两种:字节流和字符流. IO流按流向分为:输 ...

  5. Bootsrap Table表格分页

    一 bootsrap简介 Bootstrap,来自 Twitter,是目前很受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加 ...

  6. css悬浮右侧悬浮

    <html><head><title>CSSDemo</title><style type"text/css"> .ho ...

  7. DBCP数据库连接池原理分析

    在比较大的项目中,需要不断的从数据库中获取数据,Java中则使用JDBC连接数据库,但是获取数据库的连接可是相当耗时的操作,每次连接数据库都获得 .销毁数据库连接,将是很大的一个开销.为了解决这种开销 ...

  8. MySQL(五)

    一.视图 视图是一个虚拟表(非真实存在),其本质是根据SQL语句获取动态的数据集,并为其命名,用户使用时只需使用名称即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的临时表摘 ...

  9. HihoCoder#1509 : 异或排序(二进制)

    题意 题目链接 Sol 挺简单的吧.考虑两个元素什么时候不满足条件 设\(a_i\)与\(a_i + 1\)最高的不同位分别为0 1,显然\(S\)的这一位必须为\(0\),否则这一位必须为\(1\) ...

  10. Could not find or load main class Hello

    在 linux 下写了一个非常简单的 Hello World 程序,编译正常,运行报错:Error: Could not find or load main class Hello 这是由于 CLAS ...