akka java程序覆盖配置 [英] akka java programmatic override configuration
问题描述
我能找到的关于Scala的几个主题是针对Scala而不是Java,并且没有一个针对远程actor。
The few topics I can find about this are for Scala, rather than Java, and none address remote actors.
我有一个基本配置文件(SERVER_CONFIG_FILE):
I have a base configuration file (SERVER_CONFIG_FILE):
Include "akka-common"
TheSystem {
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/OtherSupervisor {
remote = "akka://OtherSystem@127.0.0.1:8553"
}
}
}
remote {
transport = "akka.remote.netty.NettyRemoteTransport"
netty {
hostname = "127.0.0.1"
port = 8552
}
}
}
}
我想在我的程序中加载它,然后覆盖几个设置,但我无法弄清楚代码。类似于:
I want to load it in my program, and then override several settings, but I can't figure out the code. Something like:
private final Config serverConfig = ConfigFactory.load(SERVER_CONFIG_FILE).withValue...?
我需要覆盖akka://DroneSystem@127.0.0.1:8553的值,还有主机名。我认为主机名可以通过ComparisonSystem.akka.remote.netty.hostname来解决,但确认会有所帮助。
I need to override the value of "akka://DroneSystem@127.0.0.1:8553", and also the hostname. I think the hostname can be addressed by "ComparisonSystem.akka.remote.netty.hostname", but confirmation would help.
我真的不知道如何解决第一个问题。值,也没有java调用它来使它结合在一起。我可以从一个我能看到的例子中学习,但不是从我找到的Scala中学习,并且没有任何地址在路径中有该Actor名称。
I really do not know how to address the first value, nor what java calls to use to make it come together. I can learn from an example I can see, but not from the Scala I find, and nothing addresses having that Actor Name in the path.
提前致谢。
推荐答案
您可以这样做,请注意您使用 Config
实例使用覆盖并让它回退到您的默认配置而不是相反:
You can do that like this, note that you use the Config
instance with overrides and let it fallback to your default configuration rather than the other way around:
Config overrides = ConfigFactory.parseString("some.setting=a-value");
Config actualConfig = overrides.withFallback(ConfigFactory.load());
或者如果您不喜欢构建字符串,可以使用属性来指定覆盖:
Or if you do not like building strings you could use properties to specify your overrides:
Properties properties = new Properties();
properties.setProperty("some.setting", "a-value");
Config overrides = ConfigFactory.parseProperties(properties);
Config actualConfig = overrides.withFallback(ConfigFactory.load());
这篇关于akka java程序覆盖配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!