Subscribers

Subscribers in Akkatecture come in the form of DomainEventSubscriber. They allow you to have listeners within the actor system listening to domain events that get published from the aggregate roots.

//subscriber counts how many games have ended
public class GamesEndedSubscriber : DomainEventSubscriber,
    ISubscribeTo<GameAggregate, GameAggregateId, GameEndedEvent>
{
    public int Count { get; set;} = 0;
        
    public Task Handle(IDomainEvent<GameAggregate, GameAggregateId, GameEndedEvent> domainEvent)
    {
        Count++;
        Logger.Info($"{Count} Games ended so far.");
        return Task.CompletedTask;
    }
}

One can do absolutely anything from these subscribers, persist projections (otherwise known as read models), do distributed calculations, or they can be used to push data into message queues to notify other domain service boundaries, or micro services. Do take note, if your subscription actor is doing "dangerous" work, like doing I/O, consider applying the error kernel pattern to defer the danger of exceptions away from the subscription actor. Create a child actor that will be responsible for doing the I/O and then make that child actor susceptible to failure, let akka.net's supervision do all the work for you.

If you want a subscriber to interact between aggregate or domain boundaries, Akkatecture ships with an AggregateSaga<,,> implementation that has been specifically tailored for this use case. To learn more about sagas (otherwise known as process managers, or activities, go here)

Next, Akka →