ある JVM で HelloActor を使用して akka システムを開始し、別の JVM でクライアントからメッセージを送信しようとしました。そして、何も機能しません。どうすればそれを正しく行うべきですか?コードは次のとおりです。
シンプルサーバー
package akkaSample.severalSystems
import akka.actor.{Props, Actor, ActorSystem}
import com.typesafe.config.ConfigFactory
class HelloActor extends Actor {
override def preStart(): Unit = {
println("Hello actor started")
}
def receive = {
case "mew" => println("I said mew")
case "hello" => println("hello back at you")
case "shutdown" => context.stop(self)
case _ => println("huh?")
}
}
object Server extends App {
val root = ConfigFactory.load()
val one = root.getConfig("systemOne")
val system = ActorSystem("HelloSystem", one)
val helloActor = system.actorOf(Props[HelloActor], "HelloActor")
println (system)
println("Remote application started.")
}
シンプルクライアント
package akkaSample.severalSystems.client
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import scala.util.control.Breaks._
class Client {
}
object Client extends App {
println("started")
val root = ConfigFactory.load()
val two = root.getConfig("systemTwo")
val system = ActorSystem("mySystem", two)
//What should be there to access HelloActor?
val selection = ...
selection ! "mew"
println(selection.anchorPath)
}
構成ファイル
systemOne {
akka {
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
port = 2552
}
}
}
}
systemTwo {
akka {
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
port = 2553
}
}
}
}
ServerがClientの前に起動することを前提としています。println(selection.anchorPath)
そのようなアクターを取得しようとすると、「akka://mySystem/deadLetters」( ) を受け取るようになりましたsystem.actorSelection("akka://HelloSystem@127.0.0.1:2552/HelloActor")
では、別の JVM で ActorSystem からアクターを取得する方法は? それとも、クラスタを作成し、シード、リーダーなどを任命するまではできないのでしょうか?