Skip to content

Event Processing

This guide explains how reactors discover methods, which signatures are supported, and how event context and errors are handled.

Reactors use convention-based method discovery. Chronicle finds and invokes public methods that:

  • Accept the event type as the first parameter
  • Optionally accept EventContext as the second parameter
  • Return void, Task, Task<T>, or a synchronous side-effect type (see below)

Event parameter types must be marked with [EventType].

// Synchronous with event only
void MethodName(TEvent @event);
// Synchronous with event and context
void MethodName(TEvent @event, EventContext context);
// Async with event only
Task MethodName(TEvent @event);
// Async with event and context
Task MethodName(TEvent @event, EventContext context);
// Async returning a side-effect event
Task<TResult> MethodName(TEvent @event);
Task<TResult> MethodName(TEvent @event, EventContext context);
// Synchronous returning a side-effect event (no Task overhead)
TResult MethodName(TEvent @event);
TResult MethodName(TEvent @event, EventContext context);

TResult can be an event type or IEnumerable<TEvent>. See Returning Side Effects for the full list of supported return types and metadata resolution.

The optional EventContext parameter provides metadata about the event, including the event source ID, sequence number, timestamps, and correlation identifiers.

using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reactors;
public class AuditReactor : IReactor
{
public void AccountClosed(AccountClosed @event, EventContext context)
{
WriteAudit(@event.AccountId, context.Occurred, context.EventSourceId);
}
void WriteAudit(Guid accountId, DateTimeOffset occurred, EventSourceId eventSourceId) { }
}

Events are delivered per event source and in sequence order. Each reactor method is called for the specific event source that produced the event.

If a reactor method throws an exception, the failing event source partition is marked as failed and processing for that partition is paused. Once the underlying issue is resolved, processing resumes from the last successful event.

  • CHR0004 - Reactor method signatures
  • CHR0005 - Event parameters require [EventType]