Start from First
Subscribe and replay all events from the beginning
Overview
A new consumer joining an Events Store channel usually needs more than what happens next — it needs everything that already happened. EventStoreStartPosition.StartFromFirst solves that by replaying the channel's complete stored history before switching to live delivery, so a service can rebuild its state from scratch instead of starting with a blank slate and hoping nothing important was missed.
Under the hood, the broker walks the store from the oldest retained sequence forward, streaming each event through the SubscribeToEventsStoreAsync async stream in order, then hands off to live delivery of new events without a gap. You don't manage offsets or checkpoints yourself — the start position is set once, at subscription time, via StartPosition = EventStoreStartPosition.StartFromFirst.
Gotchas: on a long-lived channel this can mean replaying millions of events before anything new shows up, so it's the wrong choice for a consumer that only cares about "from now on" (use StartNewOnly for that). Retention and expiration policies still apply — events already purged by TTL or max-count limits are gone and won't be replayed, so "full history" only means what the store still has.
Prerequisites
- KubeMQ server running on
localhost:50000 - C# SDK installed (
dotnet add package KubeMQ.SDK.CSharp)
Code
// KubeMQ .NET SDK — Events Store: Start From First
//
// This example subscribes to an event store channel and replays all events
// from the very first message stored, then continues receiving new events.
//
// Prerequisites:
// - KubeMQ server running on localhost:50000
// - dotnet run
using KubeMQ.Sdk.Client;
using KubeMQ.Sdk.EventsStore;
using System.Text;
await using var client = new KubeMQClient(new KubeMQClientOptions
{
Address = "localhost:50000",
ClientId = "csharp-eventsstore-start-from-first-client",
});
await client.ConnectAsync();
var subscription = new EventStoreSubscription
{
Channel = "csharp-eventsstore.start-from-first",
StartPosition = EventStoreStartPosition.StartFromFirst,
};
Console.WriteLine("Subscribed with StartFromFirst — replaying all stored events...");
await foreach (var evt in client.SubscribeToEventsStoreAsync(subscription))
{
Console.WriteLine($"[Seq {evt.Sequence}] {Encoding.UTF8.GetString(evt.Body.Span)}");
}
How It Works
StartFromFirstinstructs the broker to replay the entire channel history from the very first stored event, then continue streaming new events as they are published.- This is the standard choice for a new consumer that needs to build state from scratch (e.g., event sourcing, audit log replay).
evt.Sequenceis the broker-assigned monotonic sequence number — store the last seen value to resume from a checkpoint usingStartAtSequence.- The
await foreachwith no cancellation token runs indefinitely until the process exits or the connection drops.
Related
Was this page helpful?