Skip to content

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.

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.

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);
}

View C# snippet source on GitHub

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);
}

View C# snippet source on GitHub

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);
}

View C# snippet source on GitHub

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);
}

View C# snippet source on GitHub

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.

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;

View C# snippet source on GitHub

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.