【发布时间】:2017-10-02 18:29:29
【问题描述】:
我正在尝试使用远程参与者创建一个示例 Akka 应用程序。例如,目标是创建 16 个以顺序方式交换消息的参与者(参与者 16 与参与者 15、15 到 14 等对话,1 与参与者 16 对话)。但是,我在通信方面遇到了问题,因为我一直有这个错误。
[信息] [05/04/2017 15:45:58.248] [ActorFlasks-akka.actor.default-dispatcher-4] [akka://ActorFlasks/deadLetters] 消息 [java.lang.String] 来自 演员[akka://ActorFlasks/user/16#-2022012132] 到 演员[akka://ActorFlasks/deadLetters] 未交付。 [1] 死了 遇到的字母。
为此,我运行了 16 个应用程序的终端实例,始终使用不同的配置文件。我在每个实例中创建actorsystem,如下所示:
object Main extends App {
val localId = args(0)
val configFile = getClass.getClassLoader.getResource(s"application$localId.conf").getFile
val config = ConfigFactory.parseFile(new File(configFile))
val system = ActorSystem("ActorFlasks" , config)
val remote = system.actorOf(Props[CyclonManager], name=localId)
remote ! "START"
}
一个配置文件的例子是这样的:
akka {
actor {
provider = remote
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost"
port = 50001
}
}
}
演员是这样定义的:
class CyclonManager extends Actor {
def propagateMessage(): Unit = {
val localId = self.path.name.toInt
val currentPort = 50000 + localId
val nextHopPort = if (currentPort == 50001) 50016 else currentPort - 1
val nextHopId = localId-1
val nextHopRef = context.actorSelection(s"akka.tcp://ActorFlasks@localhost:$nextHopPort/user/$nextHopId")
nextHopRef ! "NEXT"
}
override def receive: Receive = {
case "START" =>
if (self.path.name == "16") {
propagateMessage()
}
case "NEXT" =>
propagateMessage()
case _ =>
println("Unrecognized message")
}
}
这是一个让我开始的简单示例,但无论我尝试什么都无法让它工作。有人知道我哪里失败了吗?
提前谢谢你,
编辑:
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost"
port = 50015
}
}
}
【问题讨论】:
-
你确定演员 #15 存在于端口 50015 上吗?
-
除非我对如何创建演员和演员系统有错误的理解,否则我确定。
标签: scala akka actor dead-letter