KubeMQ
Client SDKsRustHow-to guidesEvents Store

Replay from Sequence

Start reading events from a specific sequence number

Overview

Replaying from a sequence number lets a consumer resume an events-store subscription from an exact point in a channel's history, instead of re-reading everything or only catching new traffic. It's the checkpoint-recovery pattern: a worker persists the last sequence it processed, and after a crash or redeploy it reopens the subscription right there — no gap, no reprocessing everything that came before.

Sequence numbers are broker-assigned per channel, starting at 1 and increasing monotonically with every stored event; they never reset unless the channel is purged. Passing EventsStoreSubscription::StartAtSequence(5) tells the broker to begin delivery at that sequence inclusive, replaying stored events from that point, then transitioning the subscription to live delivery for anything published afterward.

Gotchas: the sequence value is inclusive, so StartAtSequence(5) still delivers event 5 — off by one and you'll reprocess or silently drop a message; you must track and persist the "last processed" sequence yourself, KubeMQ doesn't checkpoint it for you; and a sequence past the current head isn't an error, you'll just get nothing until new events catch up (the value must also fit within i64 range).

Prerequisites

  • KubeMQ server running on localhost:50000
  • Rust SDK installed (cargo add kubemq)

Code

main.rs
use kubemq::prelude::*;
use kubemq::EventsStoreSubscription;
use std::time::Duration;

#[tokio::main]
async fn main() -> kubemq::Result<()> {
    let client = KubemqClient::builder()
        .host("localhost")
        .port(50000)
        .build()
        .await?;

    let channel = "rust-events-store.replay-from-sequence";

    let sub = client.subscribe_to_events_store(
        channel, "",
        EventsStoreSubscription::StartAtSequence(5),
        |event| Box::pin(async move {
            println!("Seq {}: {}", event.sequence, String::from_utf8_lossy(&event.body));
        }),
        None,
    ).await?;

    tokio::time::sleep(Duration::from_secs(5)).await;
    sub.unsubscribe().await;
    client.close().await?;
    Ok(())
}

How It Works

  • StartAtSequence(5) starts reading from sequence number 5 (inclusive).
  • The sequence value must be within i64 range; values exceeding i64::MAX return a validation error.
  • Review timeouts, channel names, and client IDs before running against shared environments.
  • Run the program while the server from the prerequisites is available.

Was this page helpful?

On this page