Why use zookeeper
As a distributed service framework, Zookeeper is mainly used to solve the consistency problem of application systems in distributed clusters. It can provide data storage based on directory node tree method similar to file system. Zookeeper's function is mainly used to maintain and monitor the state changes of stored data, and by monitoring the changes in these data states, it can achieve data-based cluster management.
zookeeper core
Zookeeper's data model is a tree structure. In the in-memory database, the contents of the entire tree are stored, including all node paths, node data, and ACL information. Zookeeper will store this data regularly on disk.
Zookeeper node features
Persistent node
The persistent node still exists even after the client for that particular znode is created. By default, all znodes are persistent unless otherwise stated.
Temporary nodes
When the client is active, temporary nodes are valid. Temporary nodes are automatically deleted when the client disconnects from the ZooKeeper collection. Therefore, only temporary nodes do not allow children. If the temporary node is deleted, the next appropriate node will fill its position. Temporary nodes play an important role in the leader election.
Sequential nodes
The sequential nodes can be persistent or temporary. When a new znode is created as a sequential node, ZooKeeper sets the path to the znode by appending a 10-bit sequence number to the original name. For example, if you create a znode with the path /myapp as a sequential node, ZooKeeper changes the path to /myapp0000000001 and sets the next serial number to 00000000002. If two sequential nodes are created simultaneously, ZooKeeper does 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 source by Netflix. Compared with the native clients provided by Zookeeper, Curator has a higher level of abstraction, simplifying 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
@Autowiredprivate CuratorFramework curatorFramework;
For details, please refer to the official document http://curator.apache.org/index.html
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.