When building the micro service platform in the bank, the
ZookeeperAs a service registry.
CAPIn terms of the theorem,
AP, but it is
APThe scenario is more suitable for the high availability of the service registry, and availability is more important than consistency.
ZookeeperPopularity is affected by
DubboAlibaba has its own service registry to cooperate with the open source
DubboHowever, the service registry did not follow
DubboOpen source together, under the constraints of the objective environment,
ZookeeperAs a service registration center, this has affected a large number of enterprises, although later, Alibaba’s official relevant team has published articles that are not recommended
ZookeeperHowever, just like rumor and rumor refutation, the scope of rumor dissemination is much higher than that of rumor refutation information.
So, if you don’t have to use it
ZookeeperIf you want to build a service registry, please watch this article selectively as a pair of
ZookeeperJust understand and study.
ZookeeperIt is still a great framework, a well deserved distributed top-level project, and unmatched in data consistency.
SpringOn the official website, I can’t help sighing the greatness of the open source community. When I studied microservices last year, only
HystrixAnd several other components have been developed to
30Multiple open source components; Today’s
Spring Cloud, already supported
Zookeeper, becoming the most popular micro service solution in the industry.
ZooKeeper: A Distributed Coordination Service for Distributed Applications.
Zookeeper: distributed coordination service for distributed applications.
ZookeeperDownload address:Releases – Apache Zookeeper
Choose a stable
ZookeeperConfiguration required before
confThere is no configuration file in the directory. This is only for learning and creating files
zoo.cfg, content and
zoo_sample.cfgConsistent, use the default configuration.
Run from the command line
ZookeeperServer (if present)
UnixPlease run in environment
.shScript, the same below).
Start the client connection.
ZookeeperThe client is a command line interface that can operate on server data
ZookeeperA picture on the official website,
ZookeeperThe internal data structure of adopts tree structure to
/Is the root node, similar to
UnixFile system, information can be stored in each node.
ZookeeperNodes are divided into permanent nodes, sequential nodes and temporary nodes, as shown in the figure below.
Permanent node: the node always exists. Unless the delete command is explicitly executed, child nodes can be created under the permanent node.
Sequential node: after the node is created,
ZookeeperAdd a serial number to the node, as shown in the figure
ZookeeperAdditional serial number. The serial number is unique under the same parent node. The format is
Temporary node: the life cycle of the node depends on the session that created it. When the client disconnects, the node will be deleted automatically. The temporary node is not allowed to have child nodes.
The temporary node here is very suitable for micro service registration center.
When the microservice starts, it acts as a client to
ZookeeperRegister and create a temporary node containing the current microservice information. When the microservice goes offline, the temporary node will be automatically deleted
ZookeeperDeletion ensures the high availability of microservices.
And the client can add listening to the node
watchThat is, the observer will notify the client when the node is updated, so as to ensure that the service list obtained by the microservice is always up-to-date.
ZookeeperI won’t explain the basic commands,
ZookeeperThe commands are nothing more than adding, deleting, updating and querying nodes. There is no need to study deeply. As a non professional application support personnel, you can simply understand them.
It is recommended to use visualization tools to
ZookeeperLearning, you can visually operate the nodes without the trouble of issuing commands.
mavenProject, add dependency:
<dependencies> <!-- Zookeeper service discovery component -- > <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> </dependency> </dependencies>
spring: application: #Application name name: sample-application cloud: zookeeper: #Zookeeper address. It is demonstrated here that only a single zookeeper node is used without cluster deployment connect-string: localhost:2181 #Service discovery discovery: #Register itself register: true #Priority registration IP prefer-ip-address: true server: port: 9000
Start the application and a lot of information will be printed
ZookeeperConnection related logs:
ZookeeperNode information of the server, in
services/sample-applicationOne is mounted under the node
UUIDThe node stores the relevant information of the microservice.
Have time to study together in the future
ZookeeperCluster and other mainstream distributed solutions.