SpringBoot-Dubbo、Zk

SpringBoot集成Dubbo、Zk

环境:zk-bin3.7 + dubbo + maven 3.6 + jdk8

资源:

zk下载链接:

http://mirror.bit.edu.cn/apache/

dubbo下载链接:

https://github.com/apache/dubbo-admin/tree/master

参考链接:

https://mp.weixin.qq.com/s?__biz=Mzg2NTAzMTExNg==&mid=2247483947&idx=1&sn=0c8efabbaf9b8ca835d862e6e0a2254f&chksm=ce610488f9168d9eee180472c9e225c737ed56075370c1174eb29ae214326a5f8e49147c2d65&mpshare=1&scene=23&srcid=04044kPwEhzRouPihMj5Ssq0&sharer_sharetime=1617515633431&sharer_shareid=c72e98ab9a95aeb3e3a558661d42198c#rd

注:参考这个博客即可,不再重复造*

项目下载地址:

https://gitee.com/empirefree/Springboot_dubbo_zk

注意点
  1. dubbo下载的类似父子项目,需要将master的pom.xml中jdk版本修改成系统jdk版本,否则会无法mvn打包,如下图

    SpringBoot-Dubbo、Zk

  2. 下载的软件版本需对应,否则很容易出现各种高低版本不兼容的情况

  3. 代码中@Server,@Reference需要注意到底是dubbo包的还是spring下的

启动流程:
  1. 运行zk-server、zk-cli

  2. java -jar dubbo-admin-0.0.1-SNAPSHOT.jar
    
    1. 访问http://localhost:7001/ ,依次启动Producer、Consumer即可
运行结果:

SpringBoot-Dubbo、Zk

SpringBoot-Dubbo、Zk

本项目的pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Consumer</artifactId>
    <version>1.0-SNAPSHOT</version>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <dependencies>
        <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>




        <!-- Dubbo Spring Boot Starter -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>
        </dependency>
        <!-- 引入zookeeper -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.7.0</version>
            <!--排除这个slf4j-log4j12-->
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>Provider</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

</project>
上一篇:zookeeper学习一-ZK简介


下一篇:ZooKeeper 会话的秘密