Skip to content

Cratis Chronicle reactors: choose an event sequence

A Cratis Chronicle reactor observes one event sequence: the ordered source of events it handles. Select the sequence that contains the events your handler needs. Without another selection, reactors read the default event log, although .NET can infer an inbox for events from another event store.

In .NET, [EventSequence] and the eventSequence parameter on [Reactor] make the selection explicit. If both are present, [EventSequence] takes precedence. An explicit selection also prevents automatic inbox routing.

Apply [EventSequence] to a .NET reactor class when the sequence is the only option you need to set:

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Reactors;
[EventType]
public record EventSequenceShipmentDispatched(string TrackingNumber);
[EventSequence("fulfillment-events")]
public class EventSequenceShipmentReactor : IReactor
{
public Task ShipmentDispatched(EventSequenceShipmentDispatched @event, EventContext context) =>
NotifyCarrierAsync(@event.TrackingNumber);
Task NotifyCarrierAsync(string trackingNumber) => Task.CompletedTask;
}

View C# snippet source on GitHub

Kotlin and Java also provide @EventSequence, which takes precedence over the eventSequence parameter on @Reactor. TypeScript uses eventSequenceId on its reactor() decorator, shown under Using the [Reactor] Attribute. Elixir’s reactor declaration has no option for a non-default event sequence.

If you already use [Reactor] to set a stable identifier, set eventSequence there too rather than adding another attribute:

using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reactors;
[EventType]
public record EventSequenceReactorAttributeShipmentDispatched(string TrackingNumber);
[Reactor(id: "shipment-reactor", eventSequence: "fulfillment-events")]
public class EventSequenceReactorAttributeShipmentReactor : IReactor
{
public Task ShipmentDispatched(EventSequenceReactorAttributeShipmentDispatched @event, EventContext context) =>
NotifyCarrierAsync(@event.TrackingNumber);
Task NotifyCarrierAsync(string trackingNumber) => Task.CompletedTask;
}

View C# snippet source on GitHub

In .NET, either declaration selects the same sequence when used on its own. Keep the selection in one place so a later edit does not leave conflicting values on the class.

Use [EventLog] in .NET to select the default event log explicitly, even when handled event types carry an [EventStore] attribute pointing elsewhere:

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Reactors;
[EventType]
public record EventSequenceLogOrderPlaced(Guid OrderId);
[EventLog]
public class EventSequenceLocalAuditReactor : IReactor
{
public Task OrderPlaced(EventSequenceLogOrderPlaced @event, EventContext context) =>
WriteAuditAsync(@event.OrderId, context.Occurred);
Task WriteAuditAsync(Guid orderId, DateTimeOffset occurred) => Task.CompletedTask;
}

View C# snippet source on GitHub

This .NET convenience prevents the handled events’ store metadata from routing the reactor to an inbox. Use it only when those events are meant to be read from the local event log.

If the events originate in another event store, choosing a local sequence is only part of the setup. Follow Subscribe Reactors to External Event Stores to configure outbox-to-inbox delivery, automatic inbox routing, and observer-level [EventStore] usage.

Set the sequence explicitly when the reactor reads a named sequence other than the default, or when you need to override .NET’s inferred inbox. An event sequence is not an event stream type: to select events by their source or stream metadata within the sequence, use reactor filtering.