Zookeeper Java API
Table of Contents
Configuration
- Maven Dependency:
Which version should we choose?
Use the version number to match the version number of the Zookeeper server. e.g. if the server is 3.8.4, use that same version for the dependency as well.
<!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.9.1</version> </dependency>
- ZooKeeper object from this dependency is our one-stop-shop for all the communication with ZooKeeper server.
- What does the
SESSION_TIMEOUT
configuration value mean? The ZooKeeper server constantly keeps checking whether the communication is active. If the ZooKeeper server does not hear anything back for longer than that period, the server will consider that the client disconnected or dead.
Configuring log level
Find out what implementation of logging, zookeeper is using. Look at the dependency tree.
[INFO] Scanning for projects...
[INFO]
[INFO] --< distributed.systems.with.zookeeper:05fault-tolerant-leader-election >--
[INFO] Building 05fault-tolerant-leader-election 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- dependency:3.6.0:tree (default-cli) @ 05fault-tolerant-leader-election ---
[INFO] distributed.systems.with.zookeeper:05fault-tolerant-leader-election:jar:1.0-SNAPSHOT
[INFO] \- org.apache.zookeeper:zookeeper:jar:3.8.4:compile
[INFO] +- org.apache.zookeeper:zookeeper-jute:jar:3.8.4:compile
[INFO] +- org.apache.yetus:audience-annotations:jar:0.12.0:compile
[INFO] +- io.netty:netty-handler:jar:4.1.105.Final:compile
[INFO] | +- io.netty:netty-common:jar:4.1.105.Final:compile
[INFO] | +- io.netty:netty-resolver:jar:4.1.105.Final:compile
[INFO] | +- io.netty:netty-buffer:jar:4.1.105.Final:compile
[INFO] | +- io.netty:netty-transport:jar:4.1.105.Final:compile
[INFO] | +- io.netty:netty-transport-native-unix-common:jar:4.1.105.Final:compile
[INFO] | \- io.netty:netty-codec:jar:4.1.105.Final:compile
[INFO] +- io.netty:netty-transport-native-epoll:jar:4.1.105.Final:compile
[INFO] | \- io.netty:netty-transport-classes-epoll:jar:4.1.105.Final:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.2.13:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.13:compile
[INFO] \- commons-io:commons-io:jar:2.11.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.109 s
[INFO] Finished at: 2024-07-14T17:05:46-04:00
[INFO] ------------------------------------------------------------------------
If it is using logback, set the logging level using logback: https://github.com/explorer436/programming-playground/blob/main/java-playground/zookeeper-examples/05fault-tolerant-leader-election/src/main/resources/logback.xml
If it is using log4j, set the logging level using log4j: https://github.com/explorer436/programming-playground/blob/main/java-playground/zookeeper-examples/05fault-tolerant-leader-election/src/main/resources/log4j.properties
Internal references
https://github.com/explorer436/programming-playground/blob/main/java-playground/zookeeper-examples/