Akka自定义主管未生效

Akka custom supervisor not taking effect

在src/main/resources/application.conf

actor {
  # The guardian "/user" will use this class to obtain its supervisorStrategy.
  # It needs to be a subclass of akka.actor.SupervisorStrategyConfigurator.
  # In addition to the default there is akka.actor.StoppingSupervisorStrategy.
  guardian-supervisor-strategy = "config.ResilientSupervisorStrategy"
}

指的是:

package config

import akka.actor._
import akka.actor.SupervisorStrategy._

final class ResilientSupervisorStrategy extends SupervisorStrategyConfigurator {
  override def create(): SupervisorStrategy = {
    OneForOneStrategy(){
      case _: ActorInitializationException ⇒ Stop
      case _: ActorKilledException         ⇒ Stop
      case _: DeathPactException           ⇒ Stop
      case _: Exception                    ⇒ Resume}
    }
  }
}

我的 Actor 是这样实例化的

object Singleton {
  val actorSystem = ActorSystem("main")
  val logger: ActorRef = actorSystem.actorOf(Props(new Logger()))
}

val miner: ActorRef = 
    Singleton.actorSystem.actorOf(Props(new Miner()))

但是miner遇到Exception时,还是会重启(还是使用默认的supervisor策略)


附带说明一下,我的演员有非常简单的内部状态。所有失败都是由于外部资源造成的(即由于服务器发送了错误的响应而未返回 Futures)因此不需要重启 actor 的默认策略。

我觉得应该是

akka.actor {
  # The guardian "/user" will use this class to obtain its supervisorStrategy.
  # It needs to be a subclass of akka.actor.SupervisorStrategyConfigurator.
  # In addition to the default there is akka.actor.StoppingSupervisorStrategy.
  guardian-supervisor-strategy = "config.ResilientSupervisorStrategy"
}