Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cluster client

ergo-aeron-cluster is an experimental Rust client for Aeron Cluster. It uses rusteron for transport and ergo-sbe-generated codecs for Aeron’s Cluster protocol.

Hobby project. Do not use it as a production substitute for official Aeron Cluster client support.

Scope

The crate implements client-side operations:

  • synchronous and poll-driven connection;
  • ingress offer and explicit try_claim;
  • egress polling into one listener: AeronCluster::poll, or controlled_poll_egress for per-fragment flow control;
  • authentication challenges and credentials;
  • keep-alives and close requests;
  • session events, administrative responses, and leader changes.

The Java Aeron process still provides the media driver, archive, consensus module, clustered services, election, recovery, and operational tooling. This crate implements none of those server-side components.

Where the crate sits between your loop and the Java cluster:

your loop, one thread
poll, keep_alive_if_due, offer
AeronCluster
offer / try_claim: ingress
poll(listener): egress
keep_alive_if_due: every message_timeout / 4,
clamped to 50–1000 ms
a 32-byte session header a message
ergo-sbe codecs
generated at build from
cluster/schemas/*.xml
rusteron-client
exclusive publication: ingress
subscription: egress
media driver at aeron_dir: Aeron's, not this crate's
The Java Aeron process provides
the media driver, archive, consensus module, clustered services, election, recovery and
operational tooling. ergo-aeron-cluster implements none of those server-side components.
member · leader
consensus module, clustered
services, archive, media driver
member · follower
member · follower
connect(): blocks
without ingress_endpoints: connect_single, one ingress channel,
blocking adds (5 s each), then the handshake until SessionEvent(OK)
with ingress_endpoints: connect_fanout, async adds to every member,
the adds and the handshake under one message_timeout deadline
connect_async(), then poll()
CreateTransport → SendConnect → PollResponse → Done:
egress and ingress added by async adds, each step
one unit of work
Failover never blocks poll
a NewLeaderEvent starts an async add to the new
leader; offers fail NotConnected until it
connects, within message_timeout
Aeron Cluster: what ergo-aeron-cluster does, and what stays in Java
ergon book · Cluster client › Scope
Client side only. The session's states: Session lifecycle, below.
Your process: Rust
Java Aeron Cluster: none of it in this crate
ingress
egress

Session lifecycle

Text alternative. The client has one ingress publication to the leader and one egress subscription. Until the handshake succeeds it is Closed.

  1. Connect. connect() offers one SessionConnectRequest, which lands once, because each request opens a session. If the cluster sends a Challenge, the client answers with a ChallengeResponse under a new correlation id. A SessionEvent(OK) that echoes the current id gives Connected. message_timeout bounds the handshake.
  2. Keep alive. poll never sends keep-alives. Call keep_alive_if_due from the same loop. While Connected, it sends a 24-byte SessionKeepAlive every message_timeout / 4, clamped to 50–1000 ms.
  3. Leader lost. When the bound egress image closes, or an offer is refused with NotConnected or Closed, the state becomes AwaitingNewLeader. new_leader_timeout bounds the wait.
  4. New leader. A NewLeaderEvent on egress carries the new term, the leader member id and every member’s ingress endpoint. The client picks the leader’s entry, adds an ingress publication there and restarts the clock, now bounded by message_timeout. Once the publication connects, the client adopts the new term and leader, and the state returns to Connected.
  5. Close. SessionEvent(CLOSED) gives PendingClose, and the same poll then moves it to Closed. An offer refused with MaxPositionExceeded gives PendingClose until the next poll. close() sends a SessionCloseRequest while Connected and goes straight to Closed.

Each message carries a 32-byte session header. Failover and close never block poll, but offers fail with NotConnected from leader loss until the new publication connects. The session closes if no NewLeaderEvent comes within new_leader_timeout, or its publication does not connect within message_timeout. This book records no failover timings. Endpoints and field values in the animation are illustrative.

Features and harness

The published crate has one feature, static, on by default. It turns on rusteron’s static feature, which links Aeron’s C into your binary, so the binary runs with no libaeron library on the loader path. To link Aeron dynamically instead, depend on the crate with default-features = false; then libaeron must be on the loader path (cargo run and cargo test put it there):

ergo-aeron-cluster = { version = "0.1", default-features = false }

rusteron builds Aeron’s C from source either way, so the build needs CMake and a C compiler. On Linux, static also links libuuid (Debian and Ubuntu: uuid-dev) and libatomic (shipped with gcc); libbsd (libbsd-dev) is needed with or without it.

Java Cluster launch support lives in the unpublished workspace crate ergo-aeron-cluster-test-harness and requires a JDK (17 or newer; CI runs Temurin 25) plus the Aeron release jars, which its build script downloads. See Java for Archive and Cluster for which Java to run the cluster on and the recommended JVM and Aeron settings:

just fetch-aeron-jars
just test-aeron-cluster-harness

The harness, examples, integration tests, reference codecs, and benchmarks are excluded from the published crate package.

Verify the crate

cargo test -p ergo-aeron-cluster
cargo clippy -p ergo-aeron-cluster --all-targets -- -D warnings
RUSTDOCFLAGS="-D warnings" cargo doc -p ergo-aeron-cluster --no-deps
cargo bench -p ergo-aeron-cluster --no-run
cargo package -p ergo-aeron-cluster --list --allow-dirty

Run just bench-cluster for the maintained codec comparisons. See sbe/BENCHMARKS.md for the common benchmark rules.

Limitations

Limitations, Aeron and rusteron versions, schema identities, failure modes and what CI runs against a live cluster: Compatibility.

Apache-2.0.