可以从配置中查找akka actor地址吗? [英] can a lookup an akka actor address from configuration?

查看:78
本文介绍了可以从配置中查找akka actor地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Akka 2.0时,是否可以将ActorRef获取到远程actor,但是我要查找的actor的地址来自配置,而不是通过编程方式指定它?我想例如使用

When using Akka 2.0, Is there a way to get an ActorRef to a remote actor but have the address of the actor I am looking up come from configuration instead of specifying it programatically? I want to, for instance use

AkkaSystem("mysystem").actorFor("akka://system@remotehost/user/whatever")

,但我希望仅通过更改
即可更改remotehost application.conf。

but I want to be able to change remotehost just by changing my application.conf.

推荐答案

您可以从 Config 中检索任意信息。 ActorSystem 中包含的对象(或者您可以自己使用 ConfigFactory 解析外部源):

You can retrieve arbitrary information from the Config object contained in the ActorSystem (or you could parse external sources with ConfigFactory yourself):

val system = AkkaSystem("mysystem")
val config = system.settings.config
val remotePath = config.getString("my-config.serviceA")
val ref = system.actorFor(remotePath)

以及在上述路径中在配置中定义一些字符串。然后,您还可以使用Config库的功能来拼凑路径(例如,将远程节点的地址等因素分解出来):

together with defining some string in the configuration at the path given above. You can then also use the power of the Config library to piece together the path (e.g. factor out the remote node’s address etc.):

my-config {
  remotenode = "akka://sys@remote.node:2134"
  serviceA = ${my-config.remotenode}/service/A
}

这篇关于可以从配置中查找akka actor地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆