akkacircuit-breakerakka-supervision

Choosing a proper actor supervisor strategy on open circuit breaker


Akka supervision strategies allows custom behavior depending on what kind of exception it thrown, so a supervisor can choose whether the failing actor should be stopped, restarted, resumed or the error is escalated to its parent. I am trying to build a custom supervisor strategy when an actor fails with CircuitBreakerOpenException and an actor needs to be restarted. If I just choose Restart strategy, the actor will be restarted immediately which doesn't make sense since it will immediately fail again within resetTimeout interval. So the correct behavior would be to wait XXX seconds and then use Restart directive. But this behavior can't be expressed in terms of actor supervision strategy.

What is the right way to implement such behavior? I can of course add a try/catch handle in the child actor implementation, but this goes against the actor supervision concept.


Solution

  • There is a back-off supervision strategy that can do what you want and some more. You can use the minBackoff argument to specify your initial wait. I should also say that this is an exponential back-off strategy so it will keep on restarting the supervised actor but will increase the backoff times should the child actor continue throw the exceptions.