Skip to content

Reactor identity when renaming or moving code

Keep a reactor’s stored id when renaming or moving its code so Cratis Chronicle retains the same observer and processing position. In C#, the default id is the full type name, including its namespace. Renaming the class or changing that namespace creates a different observer unless you pin the existing id explicitly.

Choose an explicit id before deploying a reactor that performs side effects. You can then reorganize its code without changing the observer identity. The declaration below leaves your existing handlers unchanged:

using Cratis.Chronicle.Reactors;
// For an already deployed reactor, use its existing stored observer id here.
[Reactor("MyApp.Orders.SendWelcomeEmail")]
public class SendWelcomeEmail : IReactor
{
// Keep the existing event handlers unchanged.
}

View C# snippet source on GitHub

For a reactor that is already deployed, use its current stored id. If that id is MyApp.Orders.SendWelcomeEmail, pin that exact value before moving or renaming the class. Replacing it with a friendlier name creates a new identity, even though the declaration is now explicit.

By default, a new observer catches up from the beginning of its event sequence as ordinary observation, not replay. Its handlers can repeat historical notifications or external writes. OnceOnly excludes replay, so it does not suppress this initial catch-up. If a genuinely new reactor should ignore history, use StartAtTail for its first registration. See What OnceOnly guarantees before relying on either marker.

Preserving the old id retains its processing position, but does not provide exactly-once execution. Recovery can still re-deliver an event. Use delivery-keyed duplicate protection for side effects that must not repeat; a stable id also keeps existing delivery receipts recognizable.

Use the Workbench’s Observers page or cratis chronicle observers list to compare stored ids with the ids your application declares. Inspect an apparently abandoned observer before removing it: another service or namespace may still use it.

If the identity change was accidental, put the old id back in the reactor declaration. Removing the old observer does not transfer its position to the new one or undo side effects the new one has already performed.

If the old observer is genuinely abandoned, stop all clients that subscribe to it, then remove it by its stored id:

var result = await eventStore.Observers.Remove("the-observer");
if (!result.IsRemoved)
{
Console.WriteLine($"Not removed: {result.Outcome} in namespace {result.BlockingNamespace}");
}

View C# snippet source on GitHub

Removal affects the whole event store, across namespaces, and refuses while the observer is running or subscribed anywhere. See Removing an observer.

For a C# deployment, check the .NET discovery diagnostics before registration for likely identity changes. Investigate each finding against the stored observer: a rolling deployment can hide a rename while the old instance is still subscribed.