ZooKeeper (4) Registration Center

Case

The registration center can be implemented using Eureka. This is relatively simple. You can see the previous example spring-cloud.

So how to use zookeeper to realize the registration center?

Based on spring cloud, we can also implement it very simply.

1. Use the previously built zookeeper cluster, zookeeper cluster

2, create a new maven project

1, the POM file is as follows:

 
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">

org.springframework.boot
spring-boot-starter-parent< /artifactId>
2.1.4.RELEASE



4.0.0
com.jane
zookeeper-register-server
1.0-SNAPSHOT


1.8
Greenwich.SR1< /spring-cloud.version>




org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-actuator< br />



org.springframework.cloud
spring-cloud-starter-zookeeper-discovery



org.projectlombok
lombok< br /> true


org.springframework.boot
spring -boot-starter-test
test






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







org.springframework.boot
spring-boot-maven-plugin
< /plugin>



2, the startup files are as follows:

package com.jane.zk;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableCaching
@EnableDiscoveryClient
public class OrderServiceApplication {

public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}

3. The configuration file is as follows:

spring.application.name=order-service

management.endpoints.web.exposure .include=*
management.endpoint.health.show-details=always

server.port=0

spring.cloud.zookeeper.connect-string= www.****.com:2181,www.*****.club:2181,www.*****.club:2181

After starting, check the zookeeper node h4>

1. The service nodes are located under the directory services:
zookeeper (4) registration center

2. There is a corresponding service node in the services directory
zookeeper (4) registration center

3. View the node information corresponding to the service node
zookeeper (4) registration center

So far, a service is successfully registered to zookeeper.

Leave a Comment

Your email address will not be published.