ZooKeeper backend
Latest stable Based on Leader release 0.4.0
Library module
Problem
Section titled “Problem”Implements single and group election with Apache Curator InterProcessMutex and InterProcessSemaphoreV2, including blocking, future, and coroutine APIs.
When to use it
Section titled “When to use it”Choose it when ZooKeeper/Curator is already a supported coordination plane and session-bound ownership is understood operationally.
Coordinates
Section titled “Coordinates”Artifact: io.github.bluetape4k.leader:bluetape4k-leader-zookeeper
dependencies { implementation(platform("io.github.bluetape4k:bluetape4k-dependencies:<version>")) implementation("io.github.bluetape4k.leader:bluetape4k-leader-zookeeper")}Core concepts
Section titled “Core concepts”Ephemeral recipe nodes disappear when the ZooKeeper session expires. leaseTime is accepted for Core API consistency but is not the actual release boundary. Suspend single election preserves Curator’s acquire/release owner-thread rule.
Quick start
Section titled “Quick start”val curator = CuratorFrameworkFactory.newClient(connect, retry).apply { start() }val elector = ZooKeeperLeaderElector(curator)elector.runIfLeader("daily-report") { generateReport() }API by task
Section titled “API by task”Use single/group blocking electors, async methods, suspend variants, client extensions, and factories. The Curator client is caller-owned.
Recommended patterns
Section titled “Recommended patterns”Use a dedicated base path, stable session settings, bounded retries, and idempotent actions. Treat session suspension/loss as an ownership event.
Integrations
Section titled “Integrations”Spring can consume factories. zookeeper-scheduler demonstrates a scheduled workload and client lifecycle.
Configuration
Section titled “Configuration”Configure base path, wait time, group size, Curator connection/session timeout, retry policy, ACL, and ensemble endpoints. Do not interpret Core leaseTime as ZooKeeper TTL.
Failure modes
Section titled “Failure modes”Contention skips. Connection suspension/loss, session expiry, ACL, retry exhaustion, and Curator recipe failures propagate. Session loss releases ownership independently of the action.
Operations
Section titled “Operations”Monitor connection state, session expiry, ensemble latency, retries, znode growth, group permits, and skipped work. Close Curator only during application shutdown.
Testing
Section titled “Testing”Use a real ZooKeeper container for session loss, owner-thread release, two-client contention, group permits, extension expectations, async completion, and coroutine cancellation.
Workshops and learning path
Section titled “Workshops and learning path”Run zookeeper-scheduler, then compare session-bound ownership with TTL-based Redis and lease-based etcd.
Limitations
Section titled “Limitations”No fixed TTL guarantees release at leaseTime; session timeout controls it. ZooKeeper ownership does not fence an external side effect.
Release diagrams
Section titled “Release diagrams”These diagrams are loaded directly from README assets published with the 0.4.0 release and pinned to its immutable commit. They describe this manual’s released structure and runtime flows, not later Snapshot changes. Select a preview to open the SVG at the same release commit.
leader zookeeper Class Structure diagram
Section titled “leader zookeeper Class Structure diagram”Release README: leader-zookeeper/README.md
