gpt4 book ai didi

scala - 运行 AKKA 远程 Actor 时出现 "Dead Letters encountered"错误

转载 作者:行者123 更新时间:2023-12-04 12:09:04 32 4
gpt4 key购买 nike

我试图在我的本地主机上使用 AKKA 运行远程 Actor ,但每次我得到这个错误。它说遇到死信。我在互联网上搜索并发现当 Actor 在其线程停止后收到消息时会出现此错误。所以我正在寻找一种方法来让 Actor 在远程机器上保持活力。我使用的是 akka Actor 而不是 scala Actor 。

[INFO] [09/16/2013 18:44:51.426] [run-main] [Remoting] Starting remoting

[INFO] [09/16/2013 18:44:51.688] [run-main] [Remoting] Remoting started; listening on addresses :[akka.tcp://actorSystem1@localhost:2209]

[INFO] [09/16/2013 18:44:51.759] [actorSystem2-akka.actor.default-dispatcher-5] [akka://actorSystem2/deadLetters] Message [java.lang.String] from

Actor[akka://actorSystem2/deadLetters] to Actor[akka://actorSystem2/deadLetters] 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'.

以下是代码。
import akka.actor.{Actor, Props, ActorSystem}
import com.typesafe.config.ConfigFactory
import akka.remote._

object MyApp extends App {
val actorSystem1 = ActorSystem("actorSystem1", ConfigFactory.parseString("""
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
transport = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost"
port = 2209
}
}
}
"""))


val actorSystem2 = ActorSystem("actorSystem2")


actorSystem1.actorOf(Props(new Actor {
def receive = {
case x: String =>
Thread.sleep(1000)
println("RECEIVED MESSAGE: " + x)
} }), "simplisticActor")



val remoteActor = actorSystem2.actorFor("akka://actorSystem1@localhost:2209/user/simplisticActor")

remoteActor ! "TEST 1"
remoteActor ! "TEST 2"



Thread.sleep(1000)

actorSystem1.shutdown()
actorSystem2.shutdown()
}

提前致谢。

最佳答案

我想我看到您的代码存在一些可能导致死信的问题。首先,如果您打算从 actorSystem2 查找远程系统上的参与者。进入 actorSystem1 ,那么您仍然需要为 actorSystem1 设置远程处理属性,最具体地说,您需要确保它使用 RemoteActorRefProvider .如果您不这样做,系统 2 将无法在系统 1 中查找远程参与者。一旦您进行此更改,我还将更改您的远程参与者查找:

val remoteActor = actorSystem2.actorFor("akka://actorSystem1@localhost:2209/user/simplisticActor")

到:
val remoteActor = actorSystem2.actorSelection("akka.tcp://actorSystem1@localhost:2209/user/simplisticActor")
actorFor方法已被弃用,而且我认为你离开了 .tcp akka 的一部分用于查找远程参与者的协议(protocol)。

进行这些更改,然后看看是否适合您。

关于scala - 运行 AKKA 远程 Actor 时出现 "Dead Letters encountered"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18838775/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com