akka.netakka.net-persistence

What is the order of Akka.Persistence recovery?


I've read the Akka.Persistence intro at the Petabridge blog, and I find this part of the code a little confusing:

    Recover<string>(str => _msgs.Add(str)); // from the journal
    Recover<SnapshotOffer>(offer => {
        var messages = offer.Snapshot as List<string>;
        if(messages != null) // null check
            _msgs = _msgs.Concat(messages);
    });

What you probably want to do on recovery is... first take the last snapshot, then replay messages from the journal on top of it.

But here we have two Recover() declarations, and the journal one is first. When Akka .NET executes recovery, how does the order of these Recover() methods actually play out in practice?


Solution

  • Recover is used only to register message handler within declared actor, the same way as Receive in ReceiveActor works. Therefore order of declaring recovery handlers doesn't matter.

    From comment below:

    During recovery persistent actor first asks if there are any snapshots, it can use to recover from - therefore SnapshotOffer will always be triggered before rest of events. Then it asks for events that occurred after snapshot, it received. They will be processed in order, they come from event journal and processed by the first matching Recover handler.