作为远程配置未命名的参与者
Akka remote configuration unnamed actors
我是一名新手 Akka 开发人员,我刚刚开始使用远程处理。我总是看到这种类型的配置:
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
"/mainRepository/*" {
remote = "akka.tcp://MqttRemote@127.0.0.1:2553"
}
}
}
remote {
netty.tcp {
hostname = "127.0.0.1"
}
}
remote.netty.tcp.port = 2553
}
actor 的命名位置,例如 "mainRepository" 但是如果我想创建未命名的远程 actor 怎么办?我应该在配置中指定什么?或者我可以通过在请求新演员时不在 ActorSystem 中设置名称参数来实现吗?
另外,“*”字符是什么意思?或者我在哪里可以了解有关远程配置的更多信息? (除了 akka.io)
这个配置的意思是,如果在路径 /user/mainRepository/*
下创建任何 actor 实例(也就是说,任何 children 的 actor 实例绑定到名称 /user/mainRepository
) 不应部署到本地 ActorSystem
,而应使用远程系统的远程守护进程 MqttRemote@127.0.0.1:2553
将此 actor 部署到该远程系统。所以如果我做类似的事情:
context.actorOf(Props[MyActor], "foo")
其中 context
是我的 mainRepository
actor 实例的 ActorContext
,那么 child 将被远程部署。
*
是一个通配符,可让您更笼统地了解将远程部署哪些参与者。如果配置是这样的:
"/mainRepository/foo" {
remote = "akka.tcp://MqttRemote@127.0.0.1:2553"
}
那么只有绑定到名字foo
的child会被远程部署。我的 mainRepository
演员的任何其他 children 将被部署到本地 ActorSystem
.
所以使用这种方法,使用通配符,你确实可以创建未命名的 children 并远程部署它们,只要它们的 parent 被正确命名并且该名称被配置(如在此示例中)以远程部署它 children。
如果您不喜欢使用这种配置驱动的方法,您也可以通过编程方式远程部署 actor 实例。那看起来像这样:
import akka.actor.{ Props, Deploy, Address, AddressFromURIString }
import akka.remote.RemoteScope
val address = Address("akka.tcp", "RemoteSystem", "1.2.3.4", 1234)
val ref = system.actorOf(Props[MyActor].
withDeploy(Deploy(scope = RemoteScope(address))))
在上面的代码中,MyActor的一个实例将被部署到远程节点RemoteSystem@1.2.3.4:1234
。
有关详细信息,您可以查阅远程处理文档 here。
我是一名新手 Akka 开发人员,我刚刚开始使用远程处理。我总是看到这种类型的配置:
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
"/mainRepository/*" {
remote = "akka.tcp://MqttRemote@127.0.0.1:2553"
}
}
}
remote {
netty.tcp {
hostname = "127.0.0.1"
}
}
remote.netty.tcp.port = 2553
}
actor 的命名位置,例如 "mainRepository" 但是如果我想创建未命名的远程 actor 怎么办?我应该在配置中指定什么?或者我可以通过在请求新演员时不在 ActorSystem 中设置名称参数来实现吗?
另外,“*”字符是什么意思?或者我在哪里可以了解有关远程配置的更多信息? (除了 akka.io)
这个配置的意思是,如果在路径 /user/mainRepository/*
下创建任何 actor 实例(也就是说,任何 children 的 actor 实例绑定到名称 /user/mainRepository
) 不应部署到本地 ActorSystem
,而应使用远程系统的远程守护进程 MqttRemote@127.0.0.1:2553
将此 actor 部署到该远程系统。所以如果我做类似的事情:
context.actorOf(Props[MyActor], "foo")
其中 context
是我的 mainRepository
actor 实例的 ActorContext
,那么 child 将被远程部署。
*
是一个通配符,可让您更笼统地了解将远程部署哪些参与者。如果配置是这样的:
"/mainRepository/foo" {
remote = "akka.tcp://MqttRemote@127.0.0.1:2553"
}
那么只有绑定到名字foo
的child会被远程部署。我的 mainRepository
演员的任何其他 children 将被部署到本地 ActorSystem
.
所以使用这种方法,使用通配符,你确实可以创建未命名的 children 并远程部署它们,只要它们的 parent 被正确命名并且该名称被配置(如在此示例中)以远程部署它 children。
如果您不喜欢使用这种配置驱动的方法,您也可以通过编程方式远程部署 actor 实例。那看起来像这样:
import akka.actor.{ Props, Deploy, Address, AddressFromURIString }
import akka.remote.RemoteScope
val address = Address("akka.tcp", "RemoteSystem", "1.2.3.4", 1234)
val ref = system.actorOf(Props[MyActor].
withDeploy(Deploy(scope = RemoteScope(address))))
在上面的代码中,MyActor的一个实例将被部署到远程节点RemoteSystem@1.2.3.4:1234
。
有关详细信息,您可以查阅远程处理文档 here。