Skip to content
Leader docs0.4

ZooKeeper backend

Latest stable Based on Leader release 0.4.0

Library module

Implements single and group election with Apache Curator InterProcessMutex and InterProcessSemaphoreV2, including blocking, future, and coroutine APIs.

Choose it when ZooKeeper/Curator is already a supported coordination plane and session-bound ownership is understood operationally.

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")
}

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.

val curator = CuratorFrameworkFactory.newClient(connect, retry).apply { start() }
val elector = ZooKeeperLeaderElector(curator)
elector.runIfLeader("daily-report") { generateReport() }

Use single/group blocking electors, async methods, suspend variants, client extensions, and factories. The Curator client is caller-owned.

Use a dedicated base path, stable session settings, bounded retries, and idempotent actions. Treat session suspension/loss as an ownership event.

Spring can consume factories. zookeeper-scheduler demonstrates a scheduled workload and client lifecycle.

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.

Contention skips. Connection suspension/loss, session expiry, ACL, retry exhaustion, and Curator recipe failures propagate. Session loss releases ownership independently of the action.

Monitor connection state, session expiry, ensemble latency, retries, znode growth, group permits, and skipped work. Close Curator only during application shutdown.

Use a real ZooKeeper container for session loss, owner-thread release, two-client contention, group permits, extension expectations, async completion, and coroutine cancellation.

Run zookeeper-scheduler, then compare session-bound ownership with TTL-based Redis and lease-based etcd.

No fixed TTL guarantees release at leaseTime; session timeout controls it. ZooKeeper ownership does not fence an external side effect.

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

Release README: leader-zookeeper/README.md

Elector · Suspend elector · Stable guide