Springboot - Zookeeper配置

Posted Jomini

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Springboot - Zookeeper配置相关的知识,希望对你有一定的参考价值。

Springboot 版本 2.0.3.RELEASE

github : https://github.com/szjomin/SpringBootZookeeperConfig

一、java

pom 文件 - properties

<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>

pom 文件 - denpendenies

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.13</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.10</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

pom 文件 -  dependencyManagement

       <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>

2、注解

@EnableDiscoveryClient

在application上注解

 3、配置文件

  cloud:
    zookeeper:
       connect-string: 127.0.0.1:2181   
       discovery: 
          register: true
          enable: true
          instance-id: 1
          root: /

 

 

二、启动zookeeper 服务

 

【 附:使用 zkui 实现 zookeeper 可视化 :https://www.cnblogs.com/zhangchengzi/p/10907595.html

 

以上是关于Springboot - Zookeeper配置的主要内容,如果未能解决你的问题,请参考以下文章

zookeeper:springboot+dubbo配置zk集群并测试

SpringBoot-整合Dubbo+Zookeeper

SpringBoot基于Zookeeper和Curator生成唯一ID

Springboot+dubbo+zookeeper整合

zookeeper+dubbo+springboot入门

dubbo+zookeeper下生产者和消费者配置(基于springboot开发)