Dead-letter in Akka Scala actors

倾然丶 夕夏残阳落幕 提交于 2019-12-07 08:44:38

问题


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:

[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?


回答1:


You should use a hierarchy - launch that Collector as a child of the 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.

Consider using:

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

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



来源:https://stackoverflow.com/questions/23327675/dead-letter-in-akka-scala-actors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!