Akka のランディング ページで提供されている Akka リモーティングの入門的な例は、入門として理解するのが少し難しいと思います。また、リモーティングの内外を学習するために必要なドキュメントの長さは、入門用としては不適切な構造になっています。
以下は、前述の例のコードです。アクターがローカルであるかのようにリモートでメッセージを送信できるかどうかという問題に関連して、公平なコンテキストでそのコードが何を意味するかを説明してください。単なる構成の変更。この最後のビットに関する以前の回答は、現在の Akka のドキュメントと多少矛盾しているように見えるかもしれませんが、ドキュメント自体は、まさにこの点についてやや決定的ではありません。
// ------------------------------
// config on all machines
akka {
actor {
provider = akka.remote.RemoteActorRefProvider
deployment {
/greeter {
remote = akka.tcp://MySystem@machine1:2552
}
}
}
}
// ------------------------------
// define the greeting actor and the greeting message
case class Greeting(who: String) extends Serializable
class GreetingActor extends Actor with ActorLogging {
def receive = {
case Greeting(who) ⇒ log.info("Hello " + who)
}
}
// ------------------------------
// on machine 1: empty system, target for deployment from machine 2
val system = ActorSystem("MySystem")
// ------------------------------
// on machine 2: Remote Deployment - deploying on machine1
val system = ActorSystem("MySystem")
val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
// ------------------------------
// on machine 3: Remote Lookup (logical home of “greeter” is machine2, remote deployment is transparent)
val system = ActorSystem("MySystem")
val greeter = system.actorSelection("akka.tcp://MySystem@machine2:2552/user/greeter")
greeter ! Greeting("Sonny Rollins")
したがって、上記の重要な側面も処理するこのサンプル コードの紹介的な説明は非常に役立ちます。何日も実験モードに入るのではなく、単一の JVM 内および JVM とサーバーの境界を越えて簡単にスケーリングできるアクター アーキテクチャを選択できるようになることを願っています。
ありがとう!