Akka Scala演员的死信

问题描述:

我有一个基于Scala中Akka演员的非常简单的结构,但是我一直收到关于未送达消息的警告。这是主类的代码,Collector是扩展Actor的单独类:

I have a very simple structure based on Akka actors in Scala, but I keep on receiving warnings about undelivered messages. This is the code for the main class, Collector is a separate class extending Actor:

object Executor extends App {

  class ExecutorMaster extends Actor {

    def receive() = {
      case _ => Executor.actorSystem.actorOf(Props[Collector], name = "Collector") ! true
    }

  }

  val actorSystem = ActorSystem("ReadScheduler")
  private val app = actorSystem.actorOf(Props[ExecutorMaster], name = "Executor")

  app ! true

}

消息未传递到收集器,代码的结果是:

The message is not being delivered to the Collector, the result for the code is:


[2014年4月27日18:09:05.518]
[ReadScheduler-akka.actor .default-dispatcher-3]
[akka:// ReadScheduler / user / Collector]消息[java.lang.Boolean]从
Actor [akka:// ReadScheduler / user / Executor#2127791644]发送至没有交付
演员[akka:// ReadScheduler / user / Collector#337715308]。 [1]遇到死信。此日志记录可以关闭
,也可以使用配置设置 akka.log-dead-letters
和 akka.log-dead-letters-during-shutdown进行调整。

[04/27/2014 18:09:05.518] [ReadScheduler-akka.actor.default-dispatcher-3] [akka://ReadScheduler/user/Collector] Message [java.lang.Boolean] from Actor[akka://ReadScheduler/user/Executor#2127791644] to Actor[akka://ReadScheduler/user/Collector#337715308] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

消息传递失败的原因是什么?

What can be the reason of this unsuccessful delivery of the message? Is there something that I keep on missing in the concept?

您应该使用层次结构-启动该 Collector 作为 ExecutorMaster 的子代。

You should use a hierarchy - launch that Collector as a child of the ExecutorMaster.

您在内部执行的操作 receive 方法正在尝试创建一个与另一个具有相同名称的演员,该演员是在第一个消息 ExecutorMaster 之后创建的

What you are doing inside the receive method is attempting to create an actor having the same name as another one that gets created after the first message that the ExecutorMaster receives.

考虑使用以下方法:

val collector = context.actorOf(Props[Collector], name = "Collector")
def receive = {
    case _ => collector ! true
}

还应该使用 case对象而不是用于标识 true 含义的原语。

You also ought to use a case object and not a primitive to identify the meaning of true.