Start New Only
Subscribe to a KubeMQ events store channel for new events only, skipping stored history, with the C# SDK.
Overview
Start-from-new turns a durable Events Store channel into a live-only feed — reach for it when a consumer only cares what happens from this moment forward and would rather skip a large backlog than pay to replay it. Dashboards, live notification fan-outs, and freshly-deployed services that don't need to catch up on history are the classic cases: any of the replay-from-start positions would mean churning through every historical event just to reach the live tail.
It works by setting StartPosition = EventStoreStartPosition.StartFromNew on the EventStoreSubscription passed to SubscribeToEventsStoreAsync — the broker stamps the subscription's registration time as a watermark and delivers only events published after it, ignoring everything already stored. Gotchas: there's a race between registering and the publisher sending — a publish that lands before the broker fully registers you is silently skipped, so give the subscription a moment to settle before publishing; this position can never see anything published earlier, so use a start-from-first or start-from-sequence position when you need guaranteed replay; and reconnecting doesn't resume where you left off — a fresh StartFromNew subscription starts from "now" again, with no cursor persisted across restarts.
Prerequisites
- KubeMQ server running on
localhost:50000 - C# SDK installed (
dotnet add package KubeMQ.SDK.CSharp)
Code
// KubeMQ .NET SDK — Events Store: Start New Only
//
// This example subscribes to an event store channel receiving only new events
// published after the subscription is established (no replay of history).
//
// 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-new-only-client",
});
await client.ConnectAsync();
var subscription = new EventStoreSubscription
{
Channel = "csharp-eventsstore.start-new-only",
StartPosition = EventStoreStartPosition.StartFromNew,
};
Console.WriteLine("Subscribed with StartFromNew. Waiting for new events...");
await foreach (var evt in client.SubscribeToEventsStoreAsync(subscription))
{
Console.WriteLine($"[Seq {evt.Sequence}] {Encoding.UTF8.GetString(evt.Body.Span)}");
}
How It Works
StartFromNewskips all stored history and delivers only events published after the subscription is established. The broker records the subscription time as a watermark.- This is the lowest-latency start position: no replay cost, the consumer begins processing immediately from the current head of the log.
- Use it for stateless consumers (e.g., notification dispatchers) that do not need to catch up on past events.
- The
await foreachruns indefinitely — terminate with Ctrl+C or pass aCancellationTokenfor programmatic control.
Related
Was this page helpful?