spring-cloud integrated zookeeper

zookeeper core

Zookeeper's data model is a tree structure. In the in-memory database, the content of the entire tree is stored, including all node paths, node data, and ACL information. Zookeeper will regularly store this data to disk.

zookeeper node features

persistent node

The persistent node persists even after the client that created that particular znode disconnects. By default, all znodes are persistent unless otherwise specified.

temporary node

Ephemeral nodes are valid as long as the client is active. Ephemeral nodes are automatically deleted when clients disconnect from the ZooKeeper ensemble. Therefore, only temporary nodes are not allowed to have children. If a temporary node is removed, the next suitable node will fill its position. Ephemeral nodes play an important role in leader election.

sequential node

Sequential nodes can be persistent or ephemeral. When a new znode is created as a sequential node, ZooKeeper sets the znode's path by appending a 10-digit sequence number to the original name. For example, if a znode with path /myapp is created as a sequential node, ZooKeeper will change the path to /myapp0000000001 and set the next sequential number to 0000000002. If two sequential nodes are created at the same time, ZooKeeper will not use the same number for each znode. Sequential nodes play an important role in locking and synchronization

Curator

Curator is a Zookeeper client open sourced by Netflix. Compared with the native client provided by Zookeeper, Curator has a higher level of abstraction and simplifies Zookeeper client programming.

spring-cloud-starter-zookeeper-config

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

bootstrap.yml

spring:
  cloud:
    zookeeper:
      connect-string: 192.168.3.98:2181
      enabled: true 
      

Inject CuratorFramework

@Autowired
private CuratorFramework curatorFramework;

See the official documentation http://curator.apache.org/index.html for details

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324912982&siteId=291194637