akka.netakka.net-persistence

How can I ensure that mailbox messages will not be lost if the actors process is restarted - Akka.NET?


I have readed the online documentation of the Akka.NET.

I see that the Persistence Plugin can storage the actor's state using Event Source pattern.

But I did not find anything specific about the messages in mailbox.

When one process die or restart, the actor's mailbox recover messages?


Solution

  • According to documentation and experience, not an actor state is persisted but events that changed state, which then applying after the restart of the actor.

    Messages during Persist() or Recover() are going to stash, and both mailbox and stash are saved while actor restart

    ("An actor restart replaces only the actual actor object; the contents of the mailbox is unaffected by the restart, so processing of messages will resume after the PostRestart hook returns. The message that triggered the exception will not be received again. Any message sent to an actor while it is being restarted will be queued to its mailbox as usual." and "Stashes are handled by Akka.NET out of the actor instance just like the mailbox, so if the actor dies while processing a message, the stash is preserved.")

    But it's for normal restart, take a look at AtLeastOnceDeliveryActor, maybe it's what you are looking for guaranteed delivery. And pay attention to preRestart() method to save currently processing message while restarting.