akka2使用Typesafe
Config库,可以使用ConfigFactory.load()加载配置文件,默认加载classpath下的application.conf,
application.json and
application.properties文件。ActorSystem将会把这些配置和reference.conf合并(merge)起来。
?
如果要写akka应用,将配置写在classpath根目录下的application.conf文件中。
如果要写基于akka的lib包,将配置写在jar包内的根目录下的reference.conf文件中.
问题:如果一个项目依赖多个基于akka的jar包,这些jar包中都有reference.conf,并且配置有冲突,它是怎么解决的呢?
?
可以合并config.
Returns a new value computed by merging this value with another, with keys in
this value "winning" over the other one. Only ConfigObject and Config instances
do anything in this method (they need to merge the fallback keys into
themselves). All other values just return the original value, since they
automatically override any fallback.
The semantics of merging are described
in the spec for HOCON.
Note that objects do not merge "across" non-objects;
if you write object.withFallback(nonObject).withFallback(otherObject), then
otherObject will simply be ignored. This is an intentional part of how merging
works. Both non-objects, and any object which has fallen back to a non-object,
block subsequent fallbacks.
a.withFallback(b)? //a和b合并,如果有相同的key,以a为准
?
Clone the config with only the given path (and its children) retained; all
sibling paths are removed.
a.withOnlyPath(String path)? //只取a里的path下的配置
?
Clone the config with the given path removed.
a.withoutPath(String path) //只取a里出path外的配置
?
ConfigFactory还有其他的API,用其他的方式(字符串、文件、Map、Properties、url等)加载配置文件,可以查看相应的api。
?
配置内容即可以是层级关系,也可以用”.”号分隔写成一行:
akka {
??? host = "0.0.0.0"
??? port = 9999
}
akka.host =
"0.0.0.0"
akka.port = 9999
?
配置文件还可以在java启动参数中加载:
-Dconfig.resource=/dev.conf
?
也可以用include关键字引入其他的配置。比如可以把一些通用配置写在一个common.conf文件中,在自己的配置中只写个性配置,然后include
“common”:
calculator {
? include "common"
? akka {
??? remote.netty.port = 2552
? }
}
分享到:
相关推荐
just neet some points to download
akka_2.10
Akka is a distributed computing toolkit that enables developers to build correct concurrent and distributed applications using Java and Scala with ease, applications that scale across servers and ...
IntelliJ IDEA使用SBT构建一个AKKA Scala程序
akka-kryo-serialization, 基于Kryo的Akka序列化 akka-kryo-serialization-- Scala 和Akka基于kryo的序列化程序这个库为 Scala 和Akka提供定制的基于kryo的序列化程序。 它可以用于更高效的akka远程处理。它还可以...
Akka Essentials,学习akka很好的一本书
如何使用 Akka 来构建具备高容错性、可以横向扩展的分布式网络应用程序。Akka 是一 个强大的工具集,提供了很多选项,可以对在本地机器上处理或网络远程机器上处理的 某项工作进行抽象封装,使之对开发者不可见。...
初学akka使用实例,有很好的帮助啊,可实际运行
akka-http-rest, 在 akka http上使用灵活REST服务编写示例 Akka平滑REST服务模板 例如展示如何使用Akka和Slick在Lightbend堆栈上创建反应性REST服务。示例包含实体交互的完整REST服务。插件功能:CRUD操作实体部分...
akka-quartz, 因为用Camel来安排Akka演员是愚蠢 akka石英Akka调度程序有限,并且使用 Apache camel 运行计时器是愚蠢的。 特性石英调度程序Akka演员们Fin版本使用 Akka 2.1.x 在 Scala 2.10.x/2.11.x 上使用
如何使用 Akka 来构建具备高容错性、可以横向扩展的分布式网络应用程序。Akka 是一 个强大的工具集,提供了很多选项,可以对在本地机器上处理或网络远程机器上处理的 某项工作进行抽象封装,使之对开发者不可见。...
Akka in Action shows you how to build message-oriented systems with Akka. This comprehensive, hands-on tutorial introduces each concept with a working example. You’ll start with the big picture of ...
akka实例 java实现tcp远程调用,一个服务端,一个客户端
Learning Akka Learning Akka Learning AkkaLearning Akka
Akka is Open Source and available under the Apache 2 License. Download from http://akka.io/downloads. Please note that all code samples compile, so if you want direct access to the sources, have a ...
akka 实战。akka in action。v13 2014新版。 互联网技术入门必备 清晰,非扫描。
Akka Concurrency
Chapter 2. Introducing Akka Chapter 3. Distributed Domain-Driven Design Chapter 4. Good Actor Design Chapter 5. Good Data Flow Chapter 6. Consistency and Scalability Chapter 7. Fault Tolerance Chapter...
二、Akka简单使用 1. 从创建一个scala项目说起 在D盘新建一个项目目录,比如说叫AkkaDemo。 进入AkkaDemo目录,新建一个build.gradle文件,并在文件中输入一下内容: apply plugin: 'idea' apply plugin: 'scala' ...
赠送jar包:akka-actor_2.11-2.5.19.jar; 赠送原API文档:akka-actor_2.11-2.5.19-javadoc.jar; 赠送源代码:akka-actor_2.11-2.5.19-sources.jar; 赠送Maven依赖信息文件:akka-actor_2.11-2.5.19.pom; 包含...