RemoteLookupProxyForwarder
Akka In Action book で定義されているように、Akka Remote Actor を使用してサンプルを作成しています。私の要件は、リモートでアクターを作成するようなものですが、コード構成を使用しています。RemoteLookupProxyForwarder
アクター システムが利用可能な場合はリモート アクター システムを検索し、リモート アクターを作成するのと同じように機能します。それ以外の場合は待機します。
彼の助けを借りてapplication.conf
、これは正常に行われ、アスペクト動作として正常に機能しました。
しかし、コードを使用すると、問題は、リモート アクターが使用できない場合、プロキシ アクターがアクターを検索できず、メッセージがリモート アクターに送信されると、すべてのメッセージが配信不能になります。
リモート プロキシ アクター コード:
class RemoteLookupProxyForwarder extends Actor with ActorLogging {
context.setReceiveTimeout(3 seconds)
deployAndWatch
def deployAndWatch: Unit = {
val actor = context.actorOf(Props[RemoteActorR1], "echo")
context.watch(actor)
log.info("switching to may be active state")
context.become(maybeActive(actor))
context.setReceiveTimeout(Duration.Undefined)
}
def deploying: Receive = {
case ReceiveTimeout =>
deployAndWatch
case msg => log.error(s"Ignoring message $msg, remote actor is not ready yet")
}
def maybeActive(actor: ActorRef): Receive = {
case Terminated(actor) =>
log.info(s"Actor $actor terminated.")
log.info("switching to deploying state")
context.become(deploying)
context.setReceiveTimeout(3 seconds)
deployAndWatch
case msg => actor forward msg
}
override def receive = deploying
}
object RemoteLookupProxyForwarder {
def props = Props(new RemoteLookupProxyForwarder)
def name = "forwarder"
}
リモート 1 アクター システム:
class RemoteActorR1 extends Actor with ActorLogging {
override def receive: Receive = {
case msg => log.info(s"Server Received $msg")
}
}
object RemoteActorR1 {
def main(args: Array[String]): Unit = {
val config = ConfigFactory.parseString(conf)
ActorSystem("remote-r1", config)
}
val conf =
"""
|akka {
| log-dead-letters = "OFF"
|
| actor {
| provider = "akka.remote.RemoteActorRefProvider"
| }
|
| remote {
| enabled-transports = ["akka.remote.netty.tcp"]
| netty.tcp {
| hostname = "0.0.0.0"
| port = 2551
| }
| }
|}
""".stripMargin
}
リモート 2 アクター システム:
object RemoteActorR3 extends App {
val uri = "akka.tcp://remote-r1@0.0.0.0:2551"
val remoteR1Address = AddressFromURIString(uri)
val props = Props[RemoteLookupProxyForwarder].withDeploy(
Deploy(scope = RemoteScope(remoteR1Address))
)
val conf =
"""
|akka {
| log-dead-letters = "OFF"
|
| actor {
| provider = "akka.remote.RemoteActorRefProvider"
| }
|
| remote {
| enabled-transports = ["akka.remote.netty.tcp"]
| netty.tcp {
| hostname = "0.0.0.0"
| port = 2553
| }
| }
|}
""".stripMargin
val config = ConfigFactory.parseString(conf)
val ref = ActorSystem("remote-r3", config)
val remoteR1 = ref.actorOf(props, RemoteLookupProxyForwarder.name)
Thread.sleep(30000)
println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
remoteR1 ! "Hello Dude1"
remoteR1 ! "Hello Dude2"
remoteR1 ! "Hello Dude3"
}
configを使用application.conf
すると、この例は正常に実行されます。なぜなら、config では 2 つの展開を記述していますが、これはコードの場合であり、複数の展開を定義する方法をまだ見つけることができないからです。
application.conf
複数の配置を使用した構成:
val conf =
"""
|akka {
| log-dead-letters = "OFF"
|
| actor {
| provider = "akka.remote.RemoteActorRefProvider"
|
| deployment {
| /echo {
| remote = "akka.tcp://remote-r1@0.0.0.0:2551"
| }
|
| /forwarder/echo {
| remote = "akka.tcp://remote-r1@0.0.0.0:2551"
| }
| }
| }
|
| remote {
| enabled-transports = ["akka.remote.netty.tcp"]
| netty.tcp {
| hostname = "0.0.0.0"
| port = 2552
| }
| }
|}
""".stripMargin
私の仮定は、コードでは、1 つの展開のみを定義しているため、サンプルが期待どおりに機能しないということです。では、複数のデプロイメントをどのように定義できますか?