Skip to content

Reactors

A Chronicle reactor is an observer that runs side effects when events are appended.

Reactors are observers that react to events and execute side effects. They are ideal for integrating with external systems, sending notifications, or emitting follow-up actions when events occur.

via command pipeline

Event appended

Reactor

Side effect (notify · call an API)

New command

  • Event-driven side effects - Reactors run when events are appended and can call external services or enqueue work
  • Convention-based methods - Public methods with supported signatures are discovered automatically
  • Event context access - Optional EventContext provides metadata like timestamps and identifiers
  • Event-source isolation - Events are processed per event source, in order, to keep behavior consistent

Reactors are a good fit when you need to:

  • Trigger notifications or workflows when specific events occur
  • Synchronize with external systems
  • Run validations or side effects that do not belong in projections or reducers
  • Emit follow-up events based on patterns in the event stream
using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reactors;
[EventType]
public record ReactorsIndexEmailConfirmed(string Email);
public class ReactorsIndexEmailNotificationsReactor : IReactor
{
public Task Confirmed(ReactorsIndexEmailConfirmed @event, EventContext context) =>
SendConfirmationAsync(@event.Email, context.Occurred);
Task SendConfirmationAsync(string email, DateTimeOffset occurred) => Task.CompletedTask;
}

View C# snippet source on GitHub

For composition-root registration, the .NET client can nominate a plain instance-method reactor without IReactor. Dispatch and dependency injection stay the same; see explicit artifact registration.

Reactors react to events. To react instead to a read model being added, modified or removed — with the same convention-based methods, dependencies and side effects — see Reacting to Read Model Changes.