2011-12-09 13:27:27 +01:00
|
|
|
|
.. _configuration:
|
|
|
|
|
|
|
2011-04-20 14:28:22 +12:00
|
|
|
|
Configuration
|
|
|
|
|
|
=============
|
|
|
|
|
|
|
2011-05-01 17:35:05 +02:00
|
|
|
|
.. sidebar:: Contents
|
|
|
|
|
|
|
|
|
|
|
|
.. contents:: :local:
|
|
|
|
|
|
|
2011-05-15 00:24:12 +02:00
|
|
|
|
|
2011-04-20 14:28:22 +12:00
|
|
|
|
Specifying the configuration file
|
|
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
2011-12-14 15:12:40 +01:00
|
|
|
|
If you don't specify a configuration file then Akka uses default values, corresponding to the reference
|
|
|
|
|
|
configuration files that you see below. You can specify your own configuration file to override any
|
|
|
|
|
|
property in the reference config. You only have to define the properties that differ from the default
|
2011-11-22 13:04:10 +01:00
|
|
|
|
configuration.
|
2011-04-20 14:28:22 +12:00
|
|
|
|
|
2011-12-14 15:12:40 +01:00
|
|
|
|
By default the ``ConfigFactory.load`` method is used, which will load all ``application.conf`` (and
|
2011-12-05 10:41:36 +01:00
|
|
|
|
``application.json`` and ``application.properties``) from the root of the classpath, if they exists.
|
2011-12-14 15:12:40 +01:00
|
|
|
|
It uses ``ConfigFactory.defaultOverrides``, i.e. system properties, before falling back to
|
2011-12-05 10:41:36 +01:00
|
|
|
|
application and reference configuration.
|
2011-11-29 11:50:22 +01:00
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
Note that *all* ``application.{conf,json,properties}`` classpath resources, from all directories and
|
2011-12-14 15:12:40 +01:00
|
|
|
|
jar files, are loaded and merged. Therefore it is a good practice to define separate sub-trees in the
|
2011-12-05 10:41:36 +01:00
|
|
|
|
configuration for each actor system, and grab the specific configuration when instantiating the ActorSystem.
|
2011-04-20 14:28:22 +12:00
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
::
|
2011-12-14 15:12:40 +01:00
|
|
|
|
|
|
|
|
|
|
myapp1 {
|
2011-12-13 14:29:10 +01:00
|
|
|
|
akka.loglevel = WARNING
|
2011-12-05 10:41:36 +01:00
|
|
|
|
}
|
2011-12-14 15:12:40 +01:00
|
|
|
|
myapp2 {
|
2011-12-13 14:29:10 +01:00
|
|
|
|
akka.loglevel = ERROR
|
2011-12-05 10:41:36 +01:00
|
|
|
|
}
|
2011-04-20 14:28:22 +12:00
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
.. code-block:: scala
|
2011-04-20 14:28:22 +12:00
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
val app1 = ActorSystem("MyApp1", ConfigFactory.load.getConfig("myapp1"))
|
|
|
|
|
|
val app2 = ActorSystem("MyApp2", ConfigFactory.load.getConfig("myapp2"))
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
If the system properties ``config.resource``, ``config.file``, or ``config.url`` are set, then the
|
|
|
|
|
|
classpath resource, file, or URL specified in those properties will be used rather than the default
|
|
|
|
|
|
``application.{conf,json,properties}`` classpath resources. Note that classpath resource names start
|
|
|
|
|
|
with ``/``. ``-Dconfig.resource=/dev.conf`` will load the ``dev.conf`` from the root of the classpath.
|
2011-04-20 14:28:22 +12:00
|
|
|
|
|
2011-12-14 15:12:40 +01:00
|
|
|
|
You may also specify and parse the configuration programmatically in other ways when instantiating
|
2011-12-05 10:41:36 +01:00
|
|
|
|
the ``ActorSystem``.
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-12-13 12:33:29 +01:00
|
|
|
|
.. includecode:: code/akka/docs/config/ConfigDocSpec.scala
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:include: imports,custom-config
|
|
|
|
|
|
|
|
|
|
|
|
The ``ConfigFactory`` provides several methods to parse the configuration from various sources.
|
2011-04-20 14:28:22 +12:00
|
|
|
|
|
|
|
|
|
|
Defining the configuration file
|
|
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
2011-11-22 13:04:10 +01:00
|
|
|
|
Each Akka module has a reference configuration file with the default values.
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-actor
|
|
|
|
|
|
~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-actor/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-remote
|
|
|
|
|
|
~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-remote/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
2011-12-14 15:12:40 +01:00
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-testkit
|
|
|
|
|
|
~~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-testkit/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-beanstalk-mailbox
|
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-durable-mailboxes/akka-beanstalk-mailbox/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-file-mailbox
|
|
|
|
|
|
~~~~~~~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-durable-mailboxes/akka-file-mailbox/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-mongo-mailbox
|
|
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-durable-mailboxes/akka-mongo-mailbox/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-redis-mailbox
|
|
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-durable-mailboxes/akka-redis-mailbox/src/main/resources/reference.conf
|
2011-11-22 13:04:10 +01:00
|
|
|
|
:language: none
|
|
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
akka-zookeeper-mailbox
|
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
.. literalinclude:: ../../akka-durable-mailboxes/akka-zookeeper-mailbox/src/main/resources/reference.conf
|
2011-04-20 14:28:22 +12:00
|
|
|
|
:language: none
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
2011-12-15 14:26:17 +01:00
|
|
|
|
Custom application.conf
|
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
A custom ``application.conf`` might look like this::
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
2011-11-22 13:04:10 +01:00
|
|
|
|
# In this file you can override any option defined in the reference files.
|
|
|
|
|
|
# Copy in parts of the reference files and modify as you please.
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
akka {
|
2011-12-14 15:12:40 +01:00
|
|
|
|
|
|
|
|
|
|
# Event handlers to register at boot time (Logging$DefaultLogger logs to STDOUT)
|
2011-05-01 17:35:05 +02:00
|
|
|
|
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
|
|
|
|
|
|
|
2011-12-14 15:12:40 +01:00
|
|
|
|
# Log level used by the configured loggers (see "event-handlers") as soon
|
|
|
|
|
|
# as they have been started; before that, see "stdout-loglevel"
|
|
|
|
|
|
# Options: ERROR, WARNING, INFO, DEBUG
|
|
|
|
|
|
loglevel = DEBUG
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
2011-12-14 15:12:40 +01:00
|
|
|
|
# Log level for the very basic logger activated during AkkaApplication startup
|
|
|
|
|
|
# Options: ERROR, WARNING, INFO, DEBUG
|
|
|
|
|
|
stdout-loglevel = DEBUG
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
actor {
|
2011-11-22 13:04:10 +01:00
|
|
|
|
default-dispatcher {
|
2011-12-14 15:12:40 +01:00
|
|
|
|
# Throughput for default Dispatcher, set to 1 for as fair as possible
|
|
|
|
|
|
throughput = 10
|
2011-11-22 13:04:10 +01:00
|
|
|
|
}
|
2011-05-01 17:35:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remote {
|
|
|
|
|
|
server {
|
2011-12-14 15:12:40 +01:00
|
|
|
|
# The port clients should connect to. Default is 2552 (AKKA)
|
|
|
|
|
|
port = 2562
|
2011-05-01 17:35:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-05-15 00:24:12 +02:00
|
|
|
|
|
2011-11-22 13:04:10 +01:00
|
|
|
|
Config file format
|
|
|
|
|
|
------------------
|
|
|
|
|
|
|
2011-12-13 15:28:14 +01:00
|
|
|
|
The configuration file syntax is described in the `HOCON <https://github.com/typesafehub/config/blob/master/HOCON.md>`_
|
2011-12-14 15:12:40 +01:00
|
|
|
|
specification. Note that it supports three formats; conf, json, and properties.
|
2011-11-22 13:04:10 +01:00
|
|
|
|
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
Including files
|
|
|
|
|
|
---------------
|
|
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
Sometimes it can be useful to include another configuration file, for example if you have one ``application.conf`` with all
|
|
|
|
|
|
environment independent settings and then override some settings for specific environments.
|
2011-11-29 11:50:22 +01:00
|
|
|
|
|
2011-12-14 15:12:40 +01:00
|
|
|
|
Specifying system property with ``-Dconfig.resource=/dev.conf`` will load the ``dev.conf`` file, which includes the ``application.conf``
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
dev.conf:
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
|
include "application"
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
akka {
|
2011-11-28 09:48:36 +01:00
|
|
|
|
loglevel = "DEBUG"
|
2011-05-01 17:35:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-12-13 15:28:14 +01:00
|
|
|
|
More advanced include and substitution mechanisms are explained in the `HOCON <https://github.com/typesafehub/config/blob/master/HOCON.md>`_
|
2011-12-05 10:41:36 +01:00
|
|
|
|
specification.
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-09 20:40:09 +01:00
|
|
|
|
.. _-Dakka.log-config-on-start:
|
2011-05-15 00:24:12 +02:00
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
|
Logging of Configuration
|
|
|
|
|
|
------------------------
|
2011-05-15 00:24:12 +02:00
|
|
|
|
|
2012-02-09 20:40:09 +01:00
|
|
|
|
If the system or config property ``akka.log-config-on-start`` is set to ``on``, then the
|
2011-12-14 15:12:40 +01:00
|
|
|
|
complete configuration at INFO level when the actor system is started. This is useful
|
2011-11-29 11:50:22 +01:00
|
|
|
|
when you are uncertain of what configuration is used.
|
2011-12-26 19:01:37 +01:00
|
|
|
|
|
|
|
|
|
|
If in doubt, you can also easily and nicely inspect configuration objects
|
|
|
|
|
|
before or after using them to construct an actor system:
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: scala
|
|
|
|
|
|
|
|
|
|
|
|
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
|
|
|
|
|
|
Type in expressions to have them evaluated.
|
|
|
|
|
|
Type :help for more information.
|
2012-01-20 11:30:33 +01:00
|
|
|
|
|
2011-12-26 19:01:37 +01:00
|
|
|
|
scala> import com.typesafe.config._
|
|
|
|
|
|
import com.typesafe.config._
|
2012-01-20 11:30:33 +01:00
|
|
|
|
|
2011-12-26 19:01:37 +01:00
|
|
|
|
scala> ConfigFactory.parseString("a.b=12")
|
|
|
|
|
|
res0: com.typesafe.config.Config = Config(SimpleConfigObject({"a" : {"b" : 12}}))
|
2012-01-20 11:30:33 +01:00
|
|
|
|
|
2011-12-26 19:01:37 +01:00
|
|
|
|
scala> res0.root.render
|
2012-01-20 11:30:33 +01:00
|
|
|
|
res1: java.lang.String =
|
2011-12-26 19:01:37 +01:00
|
|
|
|
{
|
|
|
|
|
|
# String: 1
|
|
|
|
|
|
"a" : {
|
|
|
|
|
|
# String: 1
|
|
|
|
|
|
"b" : 12
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
The comments preceding every item give detailed information about the origin of
|
|
|
|
|
|
the setting (file & line number) plus possible comments which were present,
|
|
|
|
|
|
e.g. in the reference configuration. The settings as merged with the reference
|
|
|
|
|
|
and parsed by the actor system can be displayed like this:
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: java
|
|
|
|
|
|
|
|
|
|
|
|
final ActorSystem system = ActorSystem.create();
|
|
|
|
|
|
println(system.settings());
|
|
|
|
|
|
// this is a shortcut for system.settings().config().root().render()
|
|
|
|
|
|
|
2012-01-30 11:48:02 +01:00
|
|
|
|
A Word About ClassLoaders
|
|
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
|
|
In several places of the configuration file it is possible to specify the
|
|
|
|
|
|
fully-qualified class name of something to be instantiated by Akka. This is
|
|
|
|
|
|
done using Java reflection, which in turn uses a :class:`ClassLoader`. Getting
|
|
|
|
|
|
the right one in challenging environments like application containers or OSGi
|
|
|
|
|
|
bundles is not always trivial, the current approach of Akka is that each
|
|
|
|
|
|
:class:`ActorSystem` implementation stores the current thread’s context class
|
|
|
|
|
|
loader (if available, otherwise just its own loader as in
|
|
|
|
|
|
``this.getClass.getClassLoader``) and uses that for all reflective accesses.
|
|
|
|
|
|
This implies that putting Akka on the boot class path will yield
|
|
|
|
|
|
:class:`NullPointerException` from strange places: this is simply not
|
|
|
|
|
|
supported.
|
2012-01-20 11:30:33 +01:00
|
|
|
|
|
|
|
|
|
|
Application specific settings
|
|
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
The configuration can also be used for application specific settings.
|
|
|
|
|
|
A good practice is to place those settings in an Extension, as described in:
|
|
|
|
|
|
|
|
|
|
|
|
* Scala API: :ref:`extending-akka-scala.settings`
|
|
|
|
|
|
* Java API: :ref:`extending-akka-java.settings`
|