【问题标题】:Akka custom supervisor not taking effectAkka 自定义主管未生效
【发布时间】:2016-05-23 04:06:32
【问题描述】:

在 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 遇到异常时,它仍然会重新启动(它仍然使用默认的主管策略)


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

【问题讨论】:

  • 你能展示你的actor实例化的代码吗?
  • 我添加了实例化代码。

标签: scala akka akka-supervision akka-actor


【解决方案1】:

我觉得应该是

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"
}

【讨论】:

  • 谢谢!我在寻找课堂上的错误而不是配置。
  • 它仍然崩溃。我也试过akka { actor { ... } }。我想我需要查看 application.conf 文件的位置。可能与类路径有关
  • 另一个问题是 IntelliJ 配置问题。我必须将该文件夹标记为 Resources 文件夹,这也意味着它必须移到 src/main 文件夹之外
  • 感谢您提供完整的解决方案。您是否将其创建为 sbt 项目? Intellij 通常会正确设置所有这些内容
  • 是一个sbt项目,但是每次重启IntelliJ都要手动标记src和resources文件夹。为了让 IntelliJ 检测这些东西,我必须遵循文件夹命名约定吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 1970-01-01
相关资源
最近更新 更多