我正在尝试使用AKKA在我的localhost上运行远程actor,但每次我都会收到此错误。它说遇到死信。我在互联网上搜索,发现当演员在线程停止后收到消息时会出现此错误。所以我正在寻找一种让演员在远程机器上保持活力的方法。我使用的是akka演员而不是scala演员。
[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()
}
提前致谢。
答案 0 :(得分:6)
我认为我发现您的代码存在一些问题,可能会导致出现问题。首先,如果您打算将远程系统上的演员从actorSystem2
查找到actorSystem1
,那么您仍然需要为actorSystem1
设置远程属性,更具体地说,您需要确保它使用RemoteActorRefProvider
。如果不这样做,系统2将无法在系统1中查找远程actor。一旦进行了此更改,我还将更改远程actor查找:
val remoteActor = actorSystem2.actorFor("akka://actorSystem1@localhost:2209/user/simplisticActor")
为:
val remoteActor = actorSystem2.actorSelection("akka.tcp://actorSystem1@localhost:2209/user/simplisticActor")
{@ 1}}方法已被弃用,我认为您还没有查看actorFor
协议的.tcp
部分来查找远程操作符。
进行这些更改,然后查看是否适合您。