Cratis Chronicle reactor filtering by event metadata
Cratis Chronicle reactor filters restrict delivery by event metadata before a handler runs. Use them when one event type serves several workflows but a reactor should handle only a subset, such as priority orders or events from one source type.
Filtering does not remove events from storage or change what other observers receive. It narrows this reactor’s subscription within its selected event sequence. Without filters, the reactor receives events of the types it handles.
Filter attributes
Section titled “Filter attributes”| Attribute | Filters by | Matches when |
|---|---|---|
[FilterEventsByTag("...")] |
Appended or static event tag | Any filter tag matches any tag on the appended event |
[EventSourceType("...")] |
Event source type set at append time | The event source type matches exactly |
[EventStreamType("...")] |
Event stream type set at append time | The event stream type matches exactly |
The table uses .NET attribute names. Set the corresponding metadata when appending the event so the filter has a value to match:
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;
[EventType]public record ReactorsFilteringOrderPlaced(decimal TotalAmount);
public class ReactorsFilteringMetadataExampleService(IEventLog eventLog){ public Task PlaceOrder(decimal totalAmount) => eventLog.Append( EventSourceId.New(), new ReactorsFilteringOrderPlaced(totalAmount), tags: ["priority"], eventSourceType: "order", eventStreamType: "fulfillment");}import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.eventSequences.AppendOptionsimport io.cratis.chronicle.eventSequences.IEventLog
@EventTypedata class ReactorsFilteringOrderPlaced(val totalAmount: Double)
class ReactorsFilteringMetadataExampleService(private val eventLog: IEventLog) { suspend fun placeOrder(eventSourceId: String, totalAmount: Double) = eventLog.append( eventSourceId, ReactorsFilteringOrderPlaced(totalAmount), AppendOptions( tags = listOf("priority"), eventSourceType = "order", eventStreamType = "fulfillment" ) )}import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.java.AppendOptionsBuilder;import io.cratis.chronicle.java.EventLogJavaBridge;
@EventTyperecord ReactorsFilteringOrderPlaced(double totalAmount) {}
class ReactorsFilteringMetadataExampleService { private final IEventLog eventLog;
ReactorsFilteringMetadataExampleService(IEventLog eventLog) { this.eventLog = eventLog; }
void placeOrder(String eventSourceId, double totalAmount) { EventLogJavaBridge.append( eventLog, eventSourceId, new ReactorsFilteringOrderPlaced(totalAmount), new AppendOptionsBuilder() .tag("priority") .eventSourceType("order") .eventStreamType("fulfillment") .build()); }}defmodule ReactorsFilteringOrderPlaced do use Cratis.Chronicle.Events.EventType, id: "reactors-filtering-order-placed"
defstruct [:total_amount]end
defmodule ReactorsFilteringMetadataExampleService do alias ReactorsFilteringOrderPlaced
def place_order(order_id, total_amount) do Cratis.Chronicle.append( order_id, %ReactorsFilteringOrderPlaced{total_amount: total_amount}, tags: ["priority"], event_source_type: "order", event_stream_type: "fulfillment" ) endendimport { eventType, IEventLog } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class ReactorsFilteringOrderPlaced { @field(Number) readonly totalAmount: number;
constructor(totalAmount: number) { this.totalAmount = totalAmount; }}
class ReactorsFilteringMetadataExampleService { constructor(private readonly eventLog: IEventLog) {}
async placeOrder(orderId: string, totalAmount: number): Promise<void> { await this.eventLog.append(orderId, new ReactorsFilteringOrderPlaced(totalAmount), { tags: ['priority'], sourceType: 'order', streamType: 'fulfillment' }); }}Filter by tag
Section titled “Filter by tag”To run a handler only for priority orders, append the event with the priority tag and configure the reactor to match that tag. In .NET, use [FilterEventsByTag]:
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;using Cratis.Chronicle.Reactors;
[EventType]public record ReactorsFilteringByTagOrderPlaced(decimal TotalAmount);
public class ReactorsFilteringByTagOrderService(IEventLog eventLog){ public Task PlacePriorityOrder(decimal totalAmount) => eventLog.Append( EventSourceId.New(), new ReactorsFilteringByTagOrderPlaced(totalAmount), tags: ["priority"]);}
[FilterEventsByTag("priority")]public class ReactorsFilteringPriorityOrderNotifier : IReactor{ public Task Placed(ReactorsFilteringByTagOrderPlaced @event, EventContext context) => Task.CompletedTask;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.eventSequences.AppendOptionsimport io.cratis.chronicle.eventSequences.IEventLogimport io.cratis.chronicle.observation.FilterEventsByTagimport io.cratis.chronicle.observation.Reactor
@EventTypedata class ReactorsFilteringByTagOrderPlaced(val totalAmount: Double)
class ReactorsFilteringByTagOrderService(private val eventLog: IEventLog) { suspend fun placePriorityOrder(eventSourceId: String, totalAmount: Double) = eventLog.append( eventSourceId, ReactorsFilteringByTagOrderPlaced(totalAmount), AppendOptions(tags = listOf("priority")) )}
@Reactor@FilterEventsByTag("priority")class ReactorsFilteringPriorityOrderNotifier { fun placed(event: ReactorsFilteringByTagOrderPlaced, context: EventContext) { }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.java.AppendOptionsBuilder;import io.cratis.chronicle.java.EventLogJavaBridge;import io.cratis.chronicle.observation.FilterEventsByTag;import io.cratis.chronicle.observation.Reactor;
@EventTyperecord ReactorsFilteringByTagOrderPlaced(double totalAmount) {}
class ReactorsFilteringByTagOrderService { private final IEventLog eventLog;
ReactorsFilteringByTagOrderService(IEventLog eventLog) { this.eventLog = eventLog; }
void placePriorityOrder(String eventSourceId, double totalAmount) { EventLogJavaBridge.append( eventLog, eventSourceId, new ReactorsFilteringByTagOrderPlaced(totalAmount), new AppendOptionsBuilder().tag("priority").build()); }}
@Reactor@FilterEventsByTag("priority")class ReactorsFilteringPriorityOrderNotifier { void placed(ReactorsFilteringByTagOrderPlaced event, EventContext context) { }}Elixir does not support this workflow yet.import { EventContext, eventType, filterEventsByTag, IEventStore, reactor } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class ReactorsFilteringByTagOrderPlaced { @field(Number) readonly totalAmount: number;
constructor(totalAmount: number) { this.totalAmount = totalAmount; }}
class ReactorsFilteringByTagOrderService { constructor(private readonly store: IEventStore) {}
async placePriorityOrder(eventSourceId: string, totalAmount: number): Promise<void> { await this.store.eventLog.append( eventSourceId, new ReactorsFilteringByTagOrderPlaced(totalAmount), { tags: ['priority'] }); }}
@reactor()@filterEventsByTag('priority')class ReactorsFilteringPriorityOrderNotifier { async reactorsFilteringByTagOrderPlaced(_event: ReactorsFilteringByTagOrderPlaced, _context: EventContext): Promise<void> {}}The matching priority tag allows delivery. An order without that tag does not reach this reactor, even though its event type matches the handler.
Multiple filter tags
Section titled “Multiple filter tags”Multiple tag filters widen the match: an event needs any one of the configured tags, not all of them. In .NET, repeat [FilterEventsByTag] for each accepted tag:
using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record ReactorsFilteringMultiTagOrderPlaced(decimal TotalAmount);
[FilterEventsByTag("priority")][FilterEventsByTag("express")]public class ReactorsFilteringFastTrackOrderNotifier : IReactor{ public Task Placed(ReactorsFilteringMultiTagOrderPlaced @event, EventContext context) => Task.CompletedTask;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.FilterEventsByTagimport io.cratis.chronicle.observation.Reactor
@EventTypedata class ReactorsFilteringMultiTagOrderPlaced(val totalAmount: Double)
@Reactor@FilterEventsByTag("priority")@FilterEventsByTag("express")class ReactorsFilteringFastTrackOrderNotifier { fun placed( event: ReactorsFilteringMultiTagOrderPlaced, context: EventContext ) { // Only events appended with both tags reach this handler. }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.FilterEventsByTag;import io.cratis.chronicle.observation.Reactor;
@EventTyperecord ReactorsFilteringMultiTagOrderPlaced(double totalAmount) {}
@Reactor@FilterEventsByTag("priority")@FilterEventsByTag("express")class ReactorsFilteringFastTrackOrderNotifier { void placed(ReactorsFilteringMultiTagOrderPlaced event, EventContext context) { // Only events appended with both tags reach this handler. }}Elixir does not support this workflow yet.import { EventContext, eventType, filterEventsByTag, reactor } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class ReactorsFilteringMultiTagOrderPlaced { @field(Number) readonly totalAmount: number;
constructor(totalAmount: number) { this.totalAmount = totalAmount; }}
@reactor()@filterEventsByTag('priority')@filterEventsByTag('express')class ReactorsFilteringFastTrackOrderNotifier { async reactorsFilteringMultiTagOrderPlaced(_event: ReactorsFilteringMultiTagOrderPlaced, _context: EventContext): Promise<void> {}}Filter by event source type
Section titled “Filter by event source type”Use an event source type filter when the handler belongs to one category of source. In .NET, [EventSourceType] matches the event’s eventSourceType exactly:
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;using Cratis.Chronicle.Reactors;
[EventType]public record ReactorsFilteringCustomerRegistered(string EmailAddress);
public class ReactorsFilteringCustomerService(IEventLog eventLog){ public Task Register(string emailAddress) => eventLog.Append( EventSourceId.New(), new ReactorsFilteringCustomerRegistered(emailAddress), eventSourceType: "customer");}
[EventSourceType("customer")]public class ReactorsFilteringCustomerWelcomeReactor : IReactor{ public Task Registered(ReactorsFilteringCustomerRegistered @event, EventContext context) => Task.CompletedTask;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.eventSequences.AppendOptionsimport io.cratis.chronicle.eventSequences.IEventLogimport io.cratis.chronicle.observation.EventSourceTypeimport io.cratis.chronicle.observation.Reactor
@EventTypedata class ReactorsFilteringCustomerRegistered(val emailAddress: String)
class ReactorsFilteringCustomerService(private val eventLog: IEventLog) { suspend fun register(eventSourceId: String, emailAddress: String) = eventLog.append( eventSourceId, ReactorsFilteringCustomerRegistered(emailAddress), AppendOptions(eventSourceType = "customer") )}
@Reactor@EventSourceType("customer")class ReactorsFilteringCustomerWelcomeReactor { fun registered(event: ReactorsFilteringCustomerRegistered, context: EventContext) { }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.java.AppendOptionsBuilder;import io.cratis.chronicle.java.EventLogJavaBridge;import io.cratis.chronicle.observation.EventSourceType;import io.cratis.chronicle.observation.Reactor;
@EventTyperecord ReactorsFilteringCustomerRegistered(String emailAddress) {}
class ReactorsFilteringCustomerService { private final IEventLog eventLog;
ReactorsFilteringCustomerService(IEventLog eventLog) { this.eventLog = eventLog; }
void register(String eventSourceId, String emailAddress) { EventLogJavaBridge.append( eventLog, eventSourceId, new ReactorsFilteringCustomerRegistered(emailAddress), new AppendOptionsBuilder().eventSourceType("customer").build()); }}
@Reactor@EventSourceType("customer")class ReactorsFilteringCustomerWelcomeReactor { void registered(ReactorsFilteringCustomerRegistered event, EventContext context) { }}Elixir does not support this workflow yet.import { field } from '@cratis/fundamentals';import { eventType, eventSourceType, Guid, IEventLog, reactor } from '@cratis/chronicle';
@eventType()class ReactorsFilteringCustomerRegistered { @field(String) emailAddress = '';}
class ReactorsFilteringCustomerService { constructor(private readonly eventLog: IEventLog) {}
async register(emailAddress: string): Promise<void> { const result = await this.eventLog.append(Guid.create().toString(), Object.assign(new ReactorsFilteringCustomerRegistered(), { emailAddress }), { sourceType: 'customer' }); if (!result.isSuccess) throw new Error('Customer registration failed'); }}
@reactor()@eventSourceType('customer')class ReactorsFilteringCustomerWelcomeReactor { reactorsFilteringCustomerRegistered(event: ReactorsFilteringCustomerRegistered): void { console.log(`Welcome ${event.emailAddress}`); }}Filter by event stream type
Section titled “Filter by event stream type”Use a stream type filter when the handler belongs to one kind of stream. In .NET, [EventStreamType] matches the event’s stream type exactly:
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;using Cratis.Chronicle.Reactors;
[EventType]public record ReactorsFilteringPaymentCaptured(decimal Amount);
public class ReactorsFilteringPaymentsService(IEventLog eventLog){ public Task Capture(decimal amount) => eventLog.Append( EventSourceId.New(), new ReactorsFilteringPaymentCaptured(amount), eventStreamType: "payments");}
[EventStreamType("payments")]public class ReactorsFilteringPaymentReceivedNotifier : IReactor{ public Task Captured(ReactorsFilteringPaymentCaptured @event, EventContext context) => Task.CompletedTask;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.eventSequences.AppendOptionsimport io.cratis.chronicle.eventSequences.IEventLogimport io.cratis.chronicle.observation.EventStreamTypeimport io.cratis.chronicle.observation.Reactor
@EventTypedata class ReactorsFilteringPaymentCaptured(val amount: Double)
class ReactorsFilteringPaymentsService(private val eventLog: IEventLog) { suspend fun capture(eventSourceId: String, amount: Double) = eventLog.append( eventSourceId, ReactorsFilteringPaymentCaptured(amount), AppendOptions(eventStreamType = "payments") )}
@Reactor@EventStreamType("payments")class ReactorsFilteringPaymentReceivedNotifier { fun captured(event: ReactorsFilteringPaymentCaptured, context: EventContext) { }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.java.AppendOptionsBuilder;import io.cratis.chronicle.java.EventLogJavaBridge;import io.cratis.chronicle.observation.EventStreamType;import io.cratis.chronicle.observation.Reactor;
@EventTyperecord ReactorsFilteringPaymentCaptured(double amount) {}
class ReactorsFilteringPaymentsService { private final IEventLog eventLog;
ReactorsFilteringPaymentsService(IEventLog eventLog) { this.eventLog = eventLog; }
void capture(String eventSourceId, double amount) { EventLogJavaBridge.append( eventLog, eventSourceId, new ReactorsFilteringPaymentCaptured(amount), new AppendOptionsBuilder().eventStreamType("payments").build()); }}
@Reactor@EventStreamType("payments")class ReactorsFilteringPaymentReceivedNotifier { void captured(ReactorsFilteringPaymentCaptured event, EventContext context) { }}Elixir does not support this workflow yet.import { field } from '@cratis/fundamentals';import { eventType, eventStreamType, Guid, IEventLog, reactor } from '@cratis/chronicle';
@eventType()class ReactorsFilteringPaymentCaptured { @field(Number) amount = 0;}
class ReactorsFilteringPaymentsService { constructor(private readonly eventLog: IEventLog) {}
async capture(amount: number): Promise<void> { const result = await this.eventLog.append(Guid.create().toString(), Object.assign(new ReactorsFilteringPaymentCaptured(), { amount }), { streamType: 'payments' }); if (!result.isSuccess) throw new Error('Payment capture failed'); }}
@reactor()@eventStreamType('payments')class ReactorsFilteringPaymentReceivedNotifier { reactorsFilteringPaymentCaptured(event: ReactorsFilteringPaymentCaptured): void { console.log(`Payment received: ${event.amount}`); }}Combine multiple filters
Section titled “Combine multiple filters”Combine tag, source type, and stream type filters to narrow delivery further. Chronicle requires every configured category to match; the any-tag rule still applies within the tag category:
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;using Cratis.Chronicle.Reactors;
[EventType]public record ReactorsFilteringShipmentDispatched(string TrackingNumber);
public class ReactorsFilteringShippingService(IEventLog eventLog){ public Task Dispatch(string trackingNumber) => eventLog.Append( EventSourceId.New(), new ReactorsFilteringShipmentDispatched(trackingNumber), tags: ["express"], eventSourceType: "shipment", eventStreamType: "logistics");}
[FilterEventsByTag("express")][EventSourceType("shipment")][EventStreamType("logistics")]public class ReactorsFilteringExpressShipmentNotifier : IReactor{ public Task Dispatched(ReactorsFilteringShipmentDispatched @event, EventContext context) => Task.CompletedTask;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.EventSourceTypeimport io.cratis.chronicle.observation.EventStreamTypeimport io.cratis.chronicle.observation.FilterEventsByTagimport io.cratis.chronicle.observation.Reactor
@EventTypedata class ReactorsFilteringShipmentDispatched(val trackingNumber: String)
@Reactor@FilterEventsByTag("priority")@EventSourceType("Order")@EventStreamType("Fulfilment")class ReactorsFilteringShipmentNotifier { fun dispatched( event: ReactorsFilteringShipmentDispatched, context: EventContext ) { // Every filter has to match: the tag, the event source type, and the stream type. }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.EventSourceType;import io.cratis.chronicle.observation.EventStreamType;import io.cratis.chronicle.observation.FilterEventsByTag;import io.cratis.chronicle.observation.Reactor;
@EventTyperecord ReactorsFilteringShipmentDispatched(String trackingNumber) {}
@Reactor@FilterEventsByTag("priority")@EventSourceType("Order")@EventStreamType("Fulfilment")class ReactorsFilteringShipmentNotifier { void dispatched(ReactorsFilteringShipmentDispatched event, EventContext context) { // Every filter has to match: the tag, the event source type, and the stream type. }}Elixir does not support this workflow yet.import { field } from '@cratis/fundamentals';import { eventType, eventSourceType, eventStreamType, filterEventsByTag, Guid, IEventLog, reactor } from '@cratis/chronicle';
@eventType()class ReactorsFilteringShipmentDispatched { @field(String) trackingNumber = '';}
class ReactorsFilteringShippingService { constructor(private readonly eventLog: IEventLog) {}
async dispatch(trackingNumber: string): Promise<void> { const result = await this.eventLog.append(Guid.create().toString(), Object.assign(new ReactorsFilteringShipmentDispatched(), { trackingNumber }), { tags: ['express'], sourceType: 'shipment', streamType: 'logistics' }); if (!result.isSuccess) throw new Error('Shipment dispatch failed'); }}
@reactor()@filterEventsByTag('express')@eventSourceType('shipment')@eventStreamType('logistics')class ReactorsFilteringExpressShipmentNotifier { reactorsFilteringShipmentDispatched(event: ReactorsFilteringShipmentDispatched): void { console.log(`Express shipment dispatched: ${event.trackingNumber}`); }}Check the append metadata against every configured category when an expected event does not arrive. A matching tag cannot compensate for a different event source type or stream type.
Tagging the reactor vs filtering events
Section titled “Tagging the reactor vs filtering events”In .NET, [Tag] and [Tags] label the reactor itself for organization and discoverability. They do not select incoming events. Use [FilterEventsByTag] for delivery filtering:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record ReactorsFilteringTagVsFilterShipmentDispatched(string TrackingNumber);
// These labels appear on the reactor definition — they do not affect dispatch[Tag("notifications")][Tag("express")]public class ReactorsFilteringLabeledShipmentNotifier : IReactor{ public Task Dispatched(ReactorsFilteringTagVsFilterShipmentDispatched @event, EventContext context) => Task.CompletedTask;}
// These filter which events are dispatched to the reactor[FilterEventsByTag("express")][EventSourceType("shipment")]public class ReactorsFilteringFilteredShipmentNotifier : IReactor{ public Task Dispatched(ReactorsFilteringTagVsFilterShipmentDispatched @event, EventContext context) => Task.CompletedTask;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.FilterEventsByTagimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@EventTypedata class ReactorsFilteringInvoiceIssued(val amount: Double)
// @Tag labels the reactor itself and shows up in tooling - it changes nothing about// what the reactor observes. @FilterEventsByTag is what narrows the event stream.@Reactor@Tag("finance", "owned-by-billing")@FilterEventsByTag("audited")class ReactorsFilteringInvoiceAuditor { fun issued( event: ReactorsFilteringInvoiceIssued, context: EventContext ) { }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.FilterEventsByTag;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@EventTyperecord ReactorsFilteringInvoiceIssued(double amount) {}
// @Tag labels the reactor itself and shows up in tooling - it changes nothing about// what the reactor observes. @FilterEventsByTag is what narrows the event stream.@Reactor@Tag({"finance", "owned-by-billing"})@FilterEventsByTag("audited")class ReactorsFilteringInvoiceAuditor { void issued(ReactorsFilteringInvoiceIssued event, EventContext context) { }}Elixir does not support this workflow yet.TypeScript does not support this workflow yet.Detailed guides
Section titled “Detailed guides”For the matching rules and append metadata behind these examples, continue with the filter you need: