scala 运行 AKKA 远程演员时出现“遇到死信”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18838775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Dead Letters encountered" error while running AKKA remote actors
提问by nitinsh99
I am trying to run remote actors using AKKA, on my localhost, but each time I get this error. It says dead letters encountered. I searched on internet and found out that this error comes when actors receive a message after its thread is stopped. So I am looking for a way to keep the actors alive on remote machines. I am using akka actors and not the scala actors.
我正在尝试在我的本地主机上使用 AKKA 运行远程角色,但每次我都会收到此错误。它说遇到了死信。我在互联网上搜索并发现当演员在其线程停止后收到消息时会出现此错误。所以我正在寻找一种方法来让演员在远程机器上保持活力。我使用的是 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'.
Following is the code.
以下是代码。
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()
}
Thanks in advance.
提前致谢。
采纳答案by cmbaxter
I think I see a few issues with your code that might be leading to deadletters. First, if your intention is to lookup an actor on a remote system from actorSystem2into actorSystem1, then you will still need to set up remoting properties for actorSystem1, most specifically, you need to make sure it's using the RemoteActorRefProvider. If you don't do this, system 2 will not be able to lookup a remote actor in system 1. Once you make this change, I would also change your remote actor lookup from:
我想我发现您的代码存在一些可能导致死信的问题。首先,如果您打算从actorSystem2into在远程系统上查找参与者actorSystem1,那么您仍然需要为 设置远程处理属性actorSystem1,最具体地说,您需要确保它使用RemoteActorRefProvider. 如果您不这样做,系统 2 将无法在系统 1 中查找远程角色。一旦您进行此更改,我还将更改您的远程角色查找:
val remoteActor = actorSystem2.actorFor("akka://actorSystem1@localhost:2209/user/simplisticActor")
to:
到:
val remoteActor = actorSystem2.actorSelection("akka.tcp://actorSystem1@localhost:2209/user/simplisticActor")
The actorFormethod has been deprecated and also I think you left off the .tcppart of the akkaprotocol for looking up the remote actor.
该actorFor方法已被弃用,而且我认为您遗漏了用于查找远程参与者.tcp的akka协议部分。
Make these changes and then see if things work for you.
进行这些更改,然后看看是否适合您。

