This chapter introduces Zookeeper's node features and simple usage scenarios. It is precisely because of these node features that Zookeeper can be used to develop applications for different scenarios.

1. Key names of nodes at the same level are unique

Example:

$ ls /
$ create /example 2

If it already exists/examplenode, creating it again will prompt that it already exists.

2. When creating a node, the full path must be specified

Example:

$ ls /example
$ create /example/child 0
$ create /example/child/ch01 0

3. When the session is closed, temporary nodes are cleared

Example:

$ ls /example
$ create -e /example/echild 0

At the same time, view this node in terminal 2:

$ ls /example

ctrl+cAfter closing the connection in terminal 1, query terminal 2/example/echildThe node disappears.

$ ls /example

4. Automatically create sequential nodes

Example:

$ create -s -e /example 0

5. Watch mechanism: listen for node changes

The event listening mechanism is similar to the observer pattern. The watch flow is: the client registers a watcher on a node path on the server, and the client also stores the specific watcher. When the node data or child nodes change, the server notifies the client, and the client performs callback processing. Special note: once the listening event is triggered a single time, the event becomes invalid.

Tip:Refer to the Common Commands chapter for using the get command to listen with watch. Later chapters will introduce the implementation principles of watch in detail.

6. The delete command can only delete nodes one level at a time

Example:

$ ls /
$ delete /example

Tip: In newer versions, you can use thedeleteallcommand to delete recursively.

With the numerous node features mentioned above, Zookeeper can be used to develop different classic application scenarios, such as:

  • 1. Data publishing/subscription
  • 2. Load balancing
  • 3. Distributed coordination/notification
  • 4. Cluster management
  • 5. Cluster management
  • 6. Master management
  • 7. Distributed locks
  • 8. Distributed queues