Cratis Chronicle StartAtTail — skip initial reactor history
StartAtTail makes a new Cratis Chronicle reactor skip the events already in its event sequence when it first registers. Use it when deploying a notification sender or job starter should not act on old events. A reactor with a saved position keeps that position, so a restart does not skip events it has yet to handle.
Without the attribute, a new reactor starts from the beginning to catch up. Put [StartAtTail] on the C# reactor class to choose the current end of the sequence, called the tail, instead:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record WelcomeEmailRequested(string Email);
[StartAtTail]public class SendWelcomeEmails : IReactor{ public Task Requested(WelcomeEmailRequested @event) { // Runs for events appended after this reactor was first registered. // It does not run for the history that was already in the event log. return Task.CompletedTask; }}import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.StartAtTail
@EventTypedata class WelcomeEmailRequested(val email: String)
@Reactor@StartAtTailclass SendWelcomeEmails { fun requested(event: WelcomeEmailRequested) { // Runs for events appended after this reactor was first registered. // It does not run for the history that was already in the event log. }}import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.StartAtTail;
@EventTyperecord WelcomeEmailRequested(String email) {}
@Reactor@StartAtTailclass SendWelcomeEmails { void requested(WelcomeEmailRequested event) { // Runs for events appended after this reactor was first registered. // It does not run for the history that was already in the event log. }}defmodule WelcomeEmailRequested do use Chronicle.Events.EventType, id: "welcome-email-requested"
defstruct [:email]end
defmodule SendWelcomeEmails do # Begin at the tail of the event sequence the first time this reactor is # registered, so it never acts on history that predates it. use Chronicle.Reactors.Reactor, start_at_tail: true
@handles WelcomeEmailRequested
@impl true def handle(%WelcomeEmailRequested{}, _context) do # Send the email. :ok endendimport { eventType, reactor, startAtTail } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class WelcomeEmailRequested { @field(String) readonly email: string;
constructor(email: string = '') { this.email = email; }}
@reactor()@startAtTail()class SendWelcomeEmails { welcomeEmailRequested(event: WelcomeEmailRequested): void { // Runs for events appended after this reactor was first registered. // It does not run for the history that was already in the event log. }}The example observes events appended after its first registration, rather than sending welcome emails for the history already present.
What it does
Section titled “What it does”On the reactor’s first registration, Chronicle saves a position just after the current tail before observation begins. If the sequence is empty, it starts with the first event appended to it. Later registrations and restarts retain the saved position, including when events arrived while the reactor was down. Leave the attribute in place; it does not move an existing reactor forward.
The position is per namespace: each namespace has its own observer. A reactor that appears in a new namespace starts at that namespace’s tail.
The tail belongs to whichever event sequence the reactor observes, including a named sequence or an inbox. For an inbox, events still waiting in the upstream source are not skipped by this setting. Once forwarded, they are new events in the sequence the reactor observes.
An explicit replay still reads history from the beginning. StartAtTail chooses only the initial position; it does not turn off replay.
Compared with OnceOnly
Section titled “Compared with OnceOnly”OnceOnly skips a handler during replay, not during the initial catch-up. Catching up a newly registered reactor is ordinary observation, so OnceOnly alone still runs the handler against existing history.
| Marker | When it applies | What it does |
|---|---|---|
OnceOnly |
Replay | Skips the marked handler for replayed events |
StartAtTail |
First registration of a new observer | Starts after the events already in its sequence |
Use StartAtTail to skip initial history. Combine it with OnceOnly when the handler should also be skipped during an explicit Replay.
Neither guarantees exactly-once delivery. Recovering a failed partition delivers an event again as ordinary observation. Protect external side effects against repeated calls; the delivery identity provides a stable key for recognizing the same delivery.
Renaming a reactor
Section titled “Renaming a reactor”Chronicle recognizes a C# reactor by its id, which defaults to the type’s full name. Renaming the class or moving its namespace changes that default id and makes it a new reactor. With StartAtTail, it starts at the tail again, skipping any history present at that moment, including events the old reactor had not handled.
Before refactoring, preserve the existing id explicitly if the reactor must keep its position. Use Reactor identity and renaming to plan that change.
Server and client versions
Section titled “Server and client versions”Both the Chronicle server and the client must support StartAtTail. A server that predates it ignores the request, and the reactor catches up from the beginning. Upgrade the server first, then the clients, before relying on the attribute to suppress side effects against existing history.