zoukankan      html  css  js  c++  java
  • Spring Cloud:微服务注册入驻Zookeeper

    一.

    部分依赖:

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

     yml配置:

    server:
      port: 8004
    
    spring:
      cloud:
        zookeeper:
          connect-string: 192.168.10.137:2181
      application:
        name: cloud-provider-payment
    

     application主应用:

    @EnableDiscoveryClient//该注解用于向使用consul或者zookeeper作为注册中心时注册服务
    @SpringBootApplication
    public class PaymentMain8004 {
        public static void main(String[] args) {
            SpringApplication.run(PaymentMain8004.class,args);
        }
    }
    

     二.

    先使用docker装一个zookeeper,过程不再赘述。

    启动服务前。先观察zookeeper的节点信息

    ls /
    

     只有一个zookeeper节点

     启动服务:

    再观察zookeeper节点信息:

     多出一个services节点

     

     而services下面的cloud-provider-payment节点就是我在yml中配置的应用名

    我们再观察该节点的具体信息:(微服务的详细信息)

     格式化一下:

    三.临时节点

    那么这个在zookeeper中生成的节点时临时节点还是持久节点。

    我们关闭服务,立马观察zookeeper,发现该节点并没有立刻删除,但是过了一段时间后,节点被删除

    说明该节点是临时节点。

  • 相关阅读:
    [HDU 4828] Grids
    约瑟夫问题合集
    [POJ 1365] Prime Land
    [POJ 3270] Cow Sorting
    [POJ 1674] Sorting by Swapping
    SGU 188.Factory guard
    POJ 2942.Knights of the Round Table (双连通)
    POJ 1236.Network of Schools (强连通)
    POJ 2186.Popular Cows (强连通)
    POJ 1734.Sightseeing trip (Floyd 最小环)
  • 原文地址:https://www.cnblogs.com/wwjj4811/p/13616466.html
Copyright © 2011-2022 走看看