Label Chronicle reactors with tags
Descriptive tags in Cratis Chronicle label a reactor by its purpose, domain or owner. Use them to identify related reactors in their definitions; they do not change which events a reactor handles.
In .NET, apply [Tag] or [Tags] to the reactor class. If your task is to restrict delivery instead, filter the appended event metadata by tag, event source type, or event stream type.
Adding tags
Section titled “Adding tags”The examples below attach the same kind of descriptive metadata using one or several attributes. Choose the form that is easiest to read alongside the reactor declaration.
Single tag
Section titled “Single tag”Start with one label that describes the reactor’s responsibility:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record TaggingReactorsOrderPlaced(string CustomerId, string OrderId);
public interface ITaggingReactorsEmailService{ Task SendOrderConfirmation(string customerId, string orderId);}
[Tag("Notifications")]public class TaggingReactorsOrderConfirmationReactor(ITaggingReactorsEmailService emailService) : IReactor{ public Task Placed(TaggingReactorsOrderPlaced @event, EventContext context) => emailService.SendOrderConfirmation(@event.CustomerId, @event.OrderId);}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@EventTypedata class TaggingReactorsOrderPlaced(val customerId: String, val orderId: String)
interface TaggingReactorsEmailService { suspend fun sendOrderConfirmation(customerId: String, orderId: String)}
@Tag("Notifications")@Reactorclass TaggingReactorsOrderConfirmationReactor(private val emailService: TaggingReactorsEmailService) { suspend fun placed(event: TaggingReactorsOrderPlaced, context: EventContext) = emailService.sendOrderConfirmation(event.customerId, event.orderId)}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@EventTyperecord TaggingReactorsOrderPlaced(String customerId, String orderId) {}
interface TaggingReactorsEmailService { void sendOrderConfirmation(String customerId, String orderId);}
@Tag("Notifications")@Reactorclass TaggingReactorsOrderConfirmationReactor { private final TaggingReactorsEmailService emailService;
TaggingReactorsOrderConfirmationReactor(TaggingReactorsEmailService emailService) { this.emailService = emailService; }
void placed(TaggingReactorsOrderPlaced event, EventContext context) { emailService.sendOrderConfirmation(event.customerId(), event.orderId()); }}Elixir does not support this workflow yet.import { EventContext, eventType, onceOnly, reactor, tag } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class TaggingReactorsOrderPlaced { @field(String) readonly customerId: string; @field(String) readonly orderId: string;
constructor(customerId: string, orderId: string) { this.customerId = customerId; this.orderId = orderId; }}
interface TaggingReactorsEmailService { sendOrderConfirmation(customerId: string, orderId: string): Promise<void>;}
@reactor()@tag('Notifications')class TaggingReactorsOrderConfirmationReactor { constructor(private readonly emailService: TaggingReactorsEmailService) {}
@onceOnly() async taggingReactorsOrderPlaced(event: TaggingReactorsOrderPlaced, _context: EventContext): Promise<void> { await this.emailService.sendOrderConfirmation(event.customerId, event.orderId); }}Multiple tags (single attribute)
Section titled “Multiple tags (single attribute)”Pass several labels to one attribute when the reactor belongs to more than one category:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record TaggingReactorsCustomerRegistered(string Email, string Name);
public interface ITaggingReactorsWelcomeEmailService{ Task SendWelcomeEmail(string email, string name);}
[Tag("Notifications", "Customer", "Email")]public class TaggingReactorsCustomerNotificationReactor(ITaggingReactorsWelcomeEmailService emailService) : IReactor{ public Task Registered(TaggingReactorsCustomerRegistered @event, EventContext context) => emailService.SendWelcomeEmail(@event.Email, @event.Name);}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@EventTypedata class TaggingReactorsCustomerRegistered(val email: String, val name: String)
interface TaggingReactorsWelcomeEmailService { suspend fun sendWelcomeEmail(email: String, name: String)}
@Tag("Notifications", "Customer", "Email")@Reactorclass TaggingReactorsCustomerNotificationReactor(private val emailService: TaggingReactorsWelcomeEmailService) { suspend fun registered(event: TaggingReactorsCustomerRegistered, context: EventContext) = emailService.sendWelcomeEmail(event.email, event.name)}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@EventTyperecord TaggingReactorsCustomerRegistered(String email, String name) {}
interface TaggingReactorsWelcomeEmailService { void sendWelcomeEmail(String email, String name);}
@Tag({"Notifications", "Customer", "Email"})@Reactorclass TaggingReactorsCustomerNotificationReactor { private final TaggingReactorsWelcomeEmailService emailService;
TaggingReactorsCustomerNotificationReactor(TaggingReactorsWelcomeEmailService emailService) { this.emailService = emailService; }
void registered(TaggingReactorsCustomerRegistered event, EventContext context) { emailService.sendWelcomeEmail(event.email(), event.name()); }}Elixir does not support this workflow yet.import { EventContext, eventType, onceOnly, reactor, tag } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class TaggingReactorsCustomerRegistered { @field(String) readonly email: string; @field(String) readonly name: string;
constructor(email: string, name: string) { this.email = email; this.name = name; }}
interface TaggingReactorsWelcomeEmailService { sendWelcomeEmail(email: string, name: string): Promise<void>;}
@reactor()@tag('Notifications', 'Customer', 'Email')class TaggingReactorsCustomerNotificationReactor { constructor(private readonly emailService: TaggingReactorsWelcomeEmailService) {}
@onceOnly() async taggingReactorsCustomerRegistered(event: TaggingReactorsCustomerRegistered, _context: EventContext): Promise<void> { await this.emailService.sendWelcomeEmail(event.email, event.name); }}Multiple tags (multiple attributes)
Section titled “Multiple tags (multiple attributes)”Repeated [Tag] attributes produce the same combined set of labels:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record TaggingReactorsProductStockChanged(string ProductId, int NewQuantity);
public interface ITaggingReactorsInventoryApi{ Task UpdateStock(string productId, int newQuantity);}
[Tag("Integration")][Tag("ExternalAPI")][Tag("Inventory")]public class TaggingReactorsInventorySyncReactor(ITaggingReactorsInventoryApi inventoryApi) : IReactor{ public Task StockChanged(TaggingReactorsProductStockChanged @event, EventContext context) => inventoryApi.UpdateStock(@event.ProductId, @event.NewQuantity);}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@EventTypedata class TaggingReactorsProductStockChanged(val productId: String, val newQuantity: Int)
interface TaggingReactorsInventoryApi { suspend fun updateStock(productId: String, newQuantity: Int)}
@Tag("Integration")@Tag("ExternalAPI")@Tag("Inventory")@Reactorclass TaggingReactorsInventorySyncReactor(private val inventoryApi: TaggingReactorsInventoryApi) { suspend fun stockChanged(event: TaggingReactorsProductStockChanged, context: EventContext) = inventoryApi.updateStock(event.productId, event.newQuantity)}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@EventTyperecord TaggingReactorsProductStockChanged(String productId, int newQuantity) {}
interface TaggingReactorsInventoryApi { void updateStock(String productId, int newQuantity);}
@Tag("Integration")@Tag("ExternalAPI")@Tag("Inventory")@Reactorclass TaggingReactorsInventorySyncReactor { private final TaggingReactorsInventoryApi inventoryApi;
TaggingReactorsInventorySyncReactor(TaggingReactorsInventoryApi inventoryApi) { this.inventoryApi = inventoryApi; }
void stockChanged(TaggingReactorsProductStockChanged event, EventContext context) { inventoryApi.updateStock(event.productId(), event.newQuantity()); }}Elixir does not support this workflow yet.import { EventContext, eventType, onceOnly, reactor, tag } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class TaggingReactorsProductStockChanged { @field(String) readonly productId: string; @field(Number) readonly newQuantity: number;
constructor(productId: string, newQuantity: number) { this.productId = productId; this.newQuantity = newQuantity; }}
interface TaggingReactorsInventoryApi { updateStock(productId: string, newQuantity: number): Promise<void>;}
@reactor()@tag('Integration')@tag('ExternalAPI')@tag('Inventory')class TaggingReactorsInventorySyncReactor { constructor(private readonly inventoryApi: TaggingReactorsInventoryApi) {}
@onceOnly() async taggingReactorsProductStockChanged(event: TaggingReactorsProductStockChanged, _context: EventContext): Promise<void> { await this.inventoryApi.updateStock(event.productId, event.newQuantity); }}Mixed approach
Section titled “Mixed approach”You can also combine repeated attributes with multiple labels on each:
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
[EventType]public record TaggingReactorsOrderShipped(string PhoneNumber, string TrackingNumber);
public interface ITaggingReactorsSmsService{ Task SendShippingNotification(string phoneNumber, string trackingNumber);}
[Tag("Notifications", "SMS")][Tag("Customer")]public class TaggingReactorsSmsNotificationReactor(ITaggingReactorsSmsService smsService) : IReactor{ public Task Shipped(TaggingReactorsOrderShipped @event, EventContext context) => smsService.SendShippingNotification(@event.PhoneNumber, @event.TrackingNumber);}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@EventTypedata class TaggingReactorsOrderShipped(val phoneNumber: String, val trackingNumber: String)
interface TaggingReactorsSmsService { suspend fun sendShippingNotification(phoneNumber: String, trackingNumber: String)}
@Tag("Notifications", "SMS")@Tag("Customer")@Reactorclass TaggingReactorsSmsNotificationReactor(private val smsService: TaggingReactorsSmsService) { suspend fun shipped(event: TaggingReactorsOrderShipped, context: EventContext) = smsService.sendShippingNotification(event.phoneNumber, event.trackingNumber)}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@EventTyperecord TaggingReactorsOrderShipped(String phoneNumber, String trackingNumber) {}
interface TaggingReactorsSmsService { void sendShippingNotification(String phoneNumber, String trackingNumber);}
@Tag({"Notifications", "SMS"})@Tag("Customer")@Reactorclass TaggingReactorsSmsNotificationReactor { private final TaggingReactorsSmsService smsService;
TaggingReactorsSmsNotificationReactor(TaggingReactorsSmsService smsService) { this.smsService = smsService; }
void shipped(TaggingReactorsOrderShipped event, EventContext context) { smsService.sendShippingNotification(event.phoneNumber(), event.trackingNumber()); }}Elixir does not support this workflow yet.import { EventContext, eventType, onceOnly, reactor, tag } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class TaggingReactorsOrderShipped { @field(String) readonly phoneNumber: string; @field(String) readonly trackingNumber: string;
constructor(phoneNumber: string, trackingNumber: string) { this.phoneNumber = phoneNumber; this.trackingNumber = trackingNumber; }}
interface TaggingReactorsSmsService { sendShippingNotification(phoneNumber: string, trackingNumber: string): Promise<void>;}
@reactor()@tag('Notifications', 'SMS')@tag('Customer')class TaggingReactorsSmsNotificationReactor { constructor(private readonly smsService: TaggingReactorsSmsService) {}
@onceOnly() async taggingReactorsOrderShipped(event: TaggingReactorsOrderShipped, _context: EventContext): Promise<void> { await this.smsService.sendShippingNotification(event.phoneNumber, event.trackingNumber); }}Best practices
Section titled “Best practices”Choose names a maintainer will recognize, such as a business domain or the team responsible for the reactor. Use the same spelling on related reactors so the labels remain useful when reading definitions. Add a tag only when it helps someone distinguish or find the reactor.
Common tag examples
Section titled “Common tag examples”These examples label reactors by categories such as domain and purpose:
using Cratis.Chronicle;using Cratis.Chronicle.Reactors;
// By integration type[Tag("Notifications", "ExternalAPI", "MessageQueue", "FileSystem")]// By domain[Tag("Sales", "Inventory", "Customer", "Shipping")]// By communication channel[Tag("Email", "SMS", "Push", "Webhook")]// By purpose[Tag("Integration", "Alerting", "Monitoring", "Automation")]// By stakeholder[Tag("Customer", "Operations", "Finance", "Support")]public class TaggingReactorsCategoryExamplesReactor : IReactor;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
// By integration type@Tag("Notifications", "ExternalAPI", "MessageQueue", "FileSystem")// By domain@Tag("Sales", "Inventory", "Customer", "Shipping")// By communication channel@Tag("Email", "SMS", "Push", "Webhook")// By purpose@Tag("Integration", "Alerting", "Monitoring", "Automation")// By stakeholder@Tag("Customer", "Operations", "Finance", "Support")@Reactorclass TaggingReactorsCategoryExamplesReactor { fun on(event: TaggingReactorsCategoryOrderPlaced) { }}
@EventTypedata class TaggingReactorsCategoryOrderPlaced(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
// By integration type@Tag({"Notifications", "ExternalAPI", "MessageQueue", "FileSystem"})// By domain@Tag({"Sales", "Inventory", "Customer", "Shipping"})// By communication channel@Tag({"Email", "SMS", "Push", "Webhook"})// By purpose@Tag({"Integration", "Alerting", "Monitoring", "Automation"})// By stakeholder@Tag({"Customer", "Operations", "Finance", "Support"})@Reactorclass TaggingReactorsCategoryExamplesReactor { void on(TaggingReactorsCategoryOrderPlaced event) { }}
@EventTyperecord TaggingReactorsCategoryOrderPlaced(String id) {}Elixir does not support this workflow yet.import { reactor, tag } from '@cratis/chronicle';
@reactor()// By integration type@tag('Notifications', 'ExternalAPI', 'MessageQueue', 'FileSystem')// By domain@tag('Sales', 'Inventory', 'Customer', 'Shipping')// By communication channel@tag('Email', 'SMS', 'Push', 'Webhook')// By purpose@tag('Integration', 'Alerting', 'Monitoring', 'Automation')// By stakeholder@tag('Customer', 'Operations', 'Finance', 'Support')class TaggingReactorsCategoryExamplesReactor {}Querying by tag
Section titled “Querying by tag”Reactor tags are stored with the reactor definition. Chronicle does not use them to activate or select reactors, so labeling a reactor analytics does not subscribe it to events tagged analytics.
To receive only events that carry a given tag, continue with event-tag filtering. That configuration is separate from the descriptive attributes shown here.
See also
Section titled “See also”- Tagging: plain and named event tags alongside observer labels
- Tagging reducers: labels on reducer definitions