1

I have small mess in my head Avoid having poisoned mailbox http://doc.akka.io/docs/akka/2.4.2/general/supervision.html

The new actor then resumes processing its mailbox, meaning that the restart is not visible outside of the actor itself with the notable exception that the message during which the failure occurred is not re-processed.

My case: actor receives the "command" to run smth. Actor tries to reach remote service. Service is unavailable. Exception is thrown. I want actor to keep going contact remote server. I don't wan't actor to skip input command which caused exception. Will Resume help me to force actor to keep going?

override val supervisorStrategy: SupervisorStrategy =
    OneForOneStrategy(maxNrOfRetries = -1, withinTimeRange = 5.minutes) {
      case _: RemoteServiceIsDownException => Resume
      case _ => Stop
    }

By Resume, I mean retry the invocation that caused the exception to be thrown. I suspect that akka Resume means keep actor instance, but not retry failed invocation

Does akka persistence means durable mailboxes?

Extending first case. Actor tries to reach remote service. Now actor is persistent. SupervisorStrategy forces Actor to continue to contact remote service. The whole JVM shuts down. Akka app is restarted. Will Actor Resume from the point where it tired desperately reach remote service?

Does akka persistence means At least once semantics?

Actor receives message. Then JVM crashes. Will parent re-receive message it was processing during crush?

Capacytron
  • 3,425
  • 6
  • 47
  • 80
  • By 'resume', do you mean retry the invocation that caused the exception to be thrown? Using Akka Persistence provides the tools for you to implement durable mailboxes, but you do not get this just by extending `PersistentActor`. The toolkit DOES offer a really great trait called `AtleastOnceDelivery` that helps you to more or less accomplish what you are describing - http://doc.akka.io/docs/akka/current/scala/persistence.html#At-Least-Once_Delivery – simonl Apr 20 '17 at 21:43
  • By 'resume', do you mean retry the invocation that caused the exception to be thrown? - yes. – Capacytron Apr 21 '17 at 08:46

1 Answers1

1

Expanding my comment:

Will Resume help me to force actor to keep going? ... By Resume, I mean retry the invocation that caused the exception to be thrown. I suspect that akka Resume means keep actor instance, but not retry failed invocation

No, I do not believe so. The Resume directive will keep the actor chugging along after your message processing failure. One way to retry the message though, is to actually just use Restart and to take advantage of an Actor's preRestart hook:

override def preRestart(t: Throwable, msgBeforeFailure: Option[Any]): Unit = {
  case t: RemoteServiceIsDownException if msgBeforeFailure.isDefined =>
     self ! msgBeforeFailure.get
  case _: =>
}

When the actor crashes, it will run this hook and offer you an opportunity to handle the message that caused it to fail.

Does akka persistence means durable mailboxes?

Not necessarily, using a persistent actor just means that the actor's domain events, and subsequently, internal state is durable, not the mailbox it uses to process messages. That being said, it is possible to implement a durable mailbox pretty easily, see below.

Does akka persistence means At least once semantics?

Again not necessarily, but the toolkit does have a trait called AtleastOnceDelivery to let you achieve this (and durable mailbox)!

See http://doc.akka.io/docs/akka/current/scala/persistence.html#At-Least-Once_Delivery

simonl
  • 1,240
  • 7
  • 19
  • awesome, thanks, I missed AtleastOnceDelivery trait in doc and didn't know about msgBeforeFailure – Capacytron Apr 21 '17 at 16:18
  • Note though that resending a message that caused the actor to crash/restart may be dangerous if the cause of the crash was the message - the actor will just crash again and repeat. – johanandren Apr 26 '17 at 07:02