akka.netakka.net-persistence

Akka.net - Loads all journal data everytime I create a new object


Every time I create a new object of type in Akka.NET. The entire Journal of that type gets loaded in the constructor

My test:

[Test, Category("Integration")]
        public async Task Should_Persist_Actor()
        {
            var model = Mocks.Fake.Contact();

            await Actors.ContactActor.Ask(new CreateContactCommand(model, "unit test", DateTime.Now));
            var context = new MyTestContext("xxx");
            using (context)
            {
                var found = context.Set<Contact>().FirstOrDefault(x => x.Id == model.Id);
                Assert.IsNotNull(found);
            }
        }

This is the constructor that keeps getting hit, once for every entry in the journal

public sealed class CreateContactCommand : AuditCommandBase<Contact, CreateContactEvent>, ICommand<Contact, CreateContactEvent>
    {
        private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
        public CreateContactCommand(Contact obj, string auditUser, DateTime auditTime) : base(obj, auditUser, auditTime)
        {
            // This gets hit for everything in the journal db
            _logger.Debug("Create Contact Command Ctor");
        }
    }

If i truncate the journal my test passes right away. If there is data in the journal, it hits the type's constructor for each item...


Solution

  • That is working as intended. When you bring an akka actor online, it will restore it's state by replaying the event journal.