我想創建一個使用遠程actor的示例Akka應用程序。目標是創建例如16個以順序方式交換消息的演員(演員16與演員15,15到14等會談,並且1與演員16會談)。但是,我在通信方面遇到了問題,因爲我連續出現此錯誤。使用Akka創建消息環的死信
[INFO] [2017年5月4日15:45:58.248] [ActorFlasks-akka.actor.default-調度-4] [阿卡:// ActorFlasks/deadLetters]消息[java.lang中。[String] from Actor [akka:// ActorFlasks/user/16#-2022012132] to Actor [akka:// ActorFlasks/deadLetters] was not delivery。 [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://[email protected]:$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嗎? – Josef
除非我對如何創建演員和演員系統有錯誤的理解,是的,我敢肯定。 – PablodeAcero