What will happen to mailbox during system failure

What happens to the mailbox when an actor gets killed.

Say I have sent 10 messages to the actor A. when it process a 3rd message my actor system gets shutdown due to system failure. In that situation what will happen to my rest of the 7 message and can I get back those messages ?

If you want to guarantee that a message is delivered and processed, and not lost due to system failure, you can use At-Least-Once-Delivery on the sending side. It has mechanisms to deal with failure both on the sending and receiving side.

You might also find Akka Persistence in general interesting, which additionally may give you a way to implement your specific requirement on the receiving side.

Thanks @ignatius

I have went through the doc that you shared At-Least-Once-Delivery but that does not meet our requirement.

I have only one actor to send a mail and it will take couple of second to process each message and I have list of recipient whom to send mail. I am feeding these recipient list from my main method.

As I mentioned above, I have 100 name list and my actor processed 10 out of them but I sent all 100 messages to the actor. In that case If JVM gets crashed then how will I educate my actor to execute rest of 90 messages when I restart my actor.

If JVM gets crashed then how will I educate my actor to execute rest of 90 messages when I restart my actor.

By persisting the state of the application while it is running, and loading the last state when it is (re)started. In your case, the state of the application is the list of remaining emails. Every time the state changes, i.e. an email has been sent, and the list changes, you have to persist that change to somewhere more permanent than memory.

You can use Akka persistence for this, which I recommend. You can use a jdbc journal with an H2 database if you don’t want an external database server. Alternatively if it’s just a tiny utility, you can write your own file-based mechanism.

1 Like