Skip to content
Andrey Leskov edited this page Aug 25, 2016 · 7 revisions

#Overview Using event sourcing and cqrs in production raises new challenges for support teams. Now engineers can not go to the database and fix some data in tables. Change user money balance or change its name, for example. Read models can be built wrong due to events lost or out-of order. People cannot understand where the problem is - in read model build, or in aggregates and internal business state, and how to fix data-relates issues. To fight this problem GridDomain provides simple and powerful support tools.

#Aggregates diagnostics

One of the top questions is "what is the domain state? how can I view it since everything is in event store and serialized?" GridDomain provides full access to aggregates via repository pattern to load and save aggregates from akka persistence journal table and using low-level deserialization without creating ActorSystem. GridDomain contains three layers of repositories to work with different level of abstraction: 1 Aggregates - AggregateRepository 2 Domain events - IRepository 3 Persistence-specific journal entries - IRepository

repositories of top level are dependent on bottom one, allowing to change behavior on any layer. ##Aggregates repository Aggregate layer is responsible for loading and saving aggregates from persistent storage. It is represented by AggregateRepository class. If there are different versions of events persisted, we should provide EventAdaptersCatalog instance with registered domain event adapters. public class AggregateRepository : IDisposable { void Save(T aggr) where T : IAggregate; T LoadAggregate(Guid id) where T : AggregateBase; }

Use it as regular repository pattern:

using(var repo = AggregateRepository.New(AkkaWriteDbConnectionString))
{
    var aggr = repo.LoadAggregate<SampleAggregate>(myId);
}

We can use it constructor to provide underlying repositories, or use static New method for default implementation based on sql persistence and wire serialization

##Domain events repository This layer is responsible for converting journal entries to domain events, and is represented as IRepository interface.

public interface IRepository<DomainEvent>:IDisposable
{
    void Save(string id, params DomainEvent[] messages);
    DomainEvent[] Load(string id);
}

There are two implementations :

  1. DomainEventsRepository - for direct table access. Is specific to sql journal and wire serializer,and dependent on IRepository repository. No actor system or akka components are involved.

  2. ActorSystemEventRepository - for access to domain events via akka persistence. Can be configured by Hocon. can be used for debugging of akka-specific problems with config. For example, event-adapters or events deserialization.

##Journal-specific repository By default GridDomain uses sql persistence and Wire serializer, and exposes this layer as RawSqlAkkaPersistenceRepository It depends on akka persistence sql journal db schema and uses EF for direct access to the table. Use it for fetching events in serialized form for manual diagnostic.

Clone this wiki locally