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-11-22 13:04:10 +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
|
|
|
|
|
configuration.
|
2011-04-20 14:28:22 +12:00
|
|
|
|
2011-12-05 10:41:36 +01:00
|
|
|
By default the ``ConfigFactory.load`` method is used, which will load all ``application.conf`` (and
|
|
|
|
|
``application.json`` and ``application.properties``) from the root of the classpath, if they exists.
|
|
|
|
|
It uses ``ConfigFactory.defaultOverrides``, i.e. system properties, before falling back to
|
|
|
|
|
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
|
|
|
|
|
jar files, are loaded and merged. Therefore it is a good practice to define separate sub-trees in the
|
|
|
|
|
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
|
|
|
::
|
|
|
|
|
|
|
|
|
|
myapp1 {
|
2011-12-13 14:29:10 +01:00
|
|
|
akka.loglevel = WARNING
|
2011-12-05 10:41:36 +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-05 10:41:36 +01:00
|
|
|
You may also specify and parse the configuration programmatically in other ways when instantiating
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*akka-actor:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-remote:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-testkit:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-beanstalk-mailbox:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-file-mailbox:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-mongo-mailbox:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-redis-mailbox:*
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
*akka-zookeeper-mailbox:*
|
|
|
|
|
|
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-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 {
|
|
|
|
|
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
|
2011-11-22 13:04:10 +01:00
|
|
|
loglevel = DEBUG # Options: ERROR, WARNING, INFO, DEBUG
|
|
|
|
|
# this level is used by the configured loggers (see "event-handlers") as soon
|
|
|
|
|
# as they have been started; before that, see "stdout-loglevel"
|
|
|
|
|
stdout-loglevel = DEBUG # Loglevel for the very basic logger activated during AkkaApplication startup
|
2011-05-01 17:35:05 +02:00
|
|
|
|
|
|
|
|
# Comma separated list of the enabled modules.
|
|
|
|
|
enabled-modules = ["camel", "remote"]
|
|
|
|
|
|
|
|
|
|
# These boot classes are loaded (and created) automatically when the Akka Microkernel boots up
|
|
|
|
|
# Can be used to bootstrap your application(s)
|
|
|
|
|
# Should be the FQN (Fully Qualified Name) of the boot class which needs to have a default constructor
|
|
|
|
|
boot = ["sample.camel.Boot",
|
|
|
|
|
"sample.myservice.Boot"]
|
|
|
|
|
|
|
|
|
|
actor {
|
2011-11-22 13:04:10 +01:00
|
|
|
default-dispatcher {
|
2011-12-13 14:29:10 +01:00
|
|
|
throughput = 10 # Throughput for default Dispatcher, set to 1 for as fair as possible
|
2011-11-22 13:04:10 +01:00
|
|
|
}
|
2011-05-01 17:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remote {
|
|
|
|
|
server {
|
|
|
|
|
port = 2562 # The port clients should connect to. Default is 2552 (AKKA)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-15 00:24:12 +02:00
|
|
|
|
2011-11-22 13:04:10 +01:00
|
|
|
Config file format
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
The configuration file syntax is described in the `HOCON <https://github.com/havocp/config/blob/master/HOCON.md>`_
|
|
|
|
|
specification. Note that it supports three formats; conf, json, and properties.
|
|
|
|
|
|
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-05 10:41:36 +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-05 10:41:36 +01:00
|
|
|
More advanced include and substitution mechanisms are explained in the `HOCON <https://github.com/havocp/config/blob/master/HOCON.md>`_
|
|
|
|
|
specification.
|
|
|
|
|
|
|
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
.. _-Dakka.logConfigOnStart:
|
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
|
|
|
|
2011-11-29 11:50:22 +01:00
|
|
|
If the system or config property ``akka.logConfigOnStart`` is set to ``on``, then the
|
|
|
|
|
complete configuration at INFO level when the actor system is started. This is useful
|
|
|
|
|
when you are uncertain of what configuration is used.
|