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

Egress listeners

Implement EgressListener (only on_message is required) and call AeronCluster::poll every loop iteration. One call reads egress, passes this session’s messages to the listener (other sessions’ are dropped), and drives the session state: failover to a new leader, the leader and message timeouts, close. A fragment_limit of 0 drives the state alone.

#![allow(unused)]
fn main() {
use ergo_aeron_cluster::{AeronCluster, ClusterError, EgressListener};

struct Fills(usize);

impl EgressListener for Fills {
    fn on_message(&mut self, _session: i64, _timestamp: i64, payload: &[u8]) {
        self.0 += payload.len();
    }
}

fn run(client: &mut AeronCluster) -> Result<(), ClusterError> {
    let mut fills = Fills(0);
    loop {
        client.poll(&mut fills, 10)?;
        client.keep_alive_if_due()?;
    }
}
}
CallbackDefaultOverride to
on_messagerequiredhandle application payloads
on_message_with_reserved_valuecalls on_messageread the Aeron header’s reserved value (a send stamp)
on_session_event, on_new_leaderignoreobserve lifecycle; the client acts on them itself
on_challenge, on_admin_responseignoreobserve auth challenges, snapshot replies
on_extension_messageignoreread frames of another template or schema

For per-fragment flow control, implement ControlledEgressListener and call AeronCluster::controlled_poll_egress: on_message and on_extension_message return a ControlledAction (Abort, Break, Commit, or Continue) matching Aeron’s ControlledFragmentHandler.Action.

A payload slice is valid only inside the callback: copy what you keep.

Protocol errors, listener panics, keep-alive failures, publication failures, and reconnect failures are returned as ClusterError. Application payloads, credentials, challenges, and binary response data remain byte slices. Text fields declared by the protocol are validated before being exposed as &str.

The high-level client, configuration, listener, state, error, offer, and claim types are the consumer-facing surface. The generated protocol codecs are also reachable, for advanced direct encode/decode, through the cluster_codec_types module, but that module is #[doc(hidden)] and not a stable API: it exists for repository tests and low-level experimentation, and its shape may change in any release. Normal applications should use AeronCluster.