Configuration

Configuration

Akka uses the Typesafe Config Library, which might also be a good choice for the configuration of your own application or library built with or without Akka. This library is implemented in Java with no external dependencies; you should have a look at its documentation (in particular about ConfigFactory), which is only summarized in the following.

Warning

If you use Akka from the Scala REPL from the 2.9.x series, and you do not provide your own ClassLoader to the ActorSystem, start the REPL with "-Yrepl-sync" to work around a deficiency in the REPLs provided Context ClassLoader.

Where configuration is read from

All configuration for Akka is held within instances of ActorSystem, or put differently, as viewed from the outside, ActorSystem is the only consumer of configuration information. While constructing an actor system, you can either pass in a Config object or not, where the second case is equivalent to passing ConfigFactory.load() (with the right class loader). This means roughly that the default is to parse all application.conf, application.json and application.properties found at the root of the class path—please refer to the aforementioned documentation for details. The actor system then merges in all reference.conf resources found at the root of the class path to form the fallback configuration, i.e. it internally uses

  1. appConfig.withFallback(ConfigFactory.defaultReference(classLoader))

The philosophy is that code never contains default values, but instead relies upon their presence in the reference.conf supplied with the library in question.

Highest precedence is given to overrides given as system properties, see the HOCON specification (near the bottom). Also noteworthy is that the application configuration—which defaults to application—may be overridden using the config.resource property (there are more, please refer to the Config docs).

Note

If you are writing an Akka application, keep you configuration in application.conf at the root of the class path. If you are writing an Akka-based library, keep its configuration in reference.conf at the root of the JAR file.

When using JarJar, OneJar, Assembly or any jar-bundler

Warning

Akka's configuration approach relies heavily on the notion of every module/jar having its own reference.conf file, all of these will be discovered by the configuration and loaded. Unfortunately this also means that if you put merge multiple jars into the same jar, you need to merge all the reference.confs as well. Otherwise all defaults will be lost and Akka will not function.

How to structure your configuration

Given that ConfigFactory.load() merges all resources with matching name from the whole class path, it is easiest to utilize that functionality and differenciate actor systems within the hierarchy of the configuration:

  1. myapp1 {
  2. akka.loglevel = WARNING
  3. my.own.setting = 43
  4. }
  5. myapp2 {
  6. akka.loglevel = ERROR
  7. app2.setting = "appname"
  8. }
  9. my.own.setting = 42
  10. my.other.setting = "hello"
  1. val config = ConfigFactory.load()
  2. val app1 = ActorSystem("MyApp1", config.getConfig("myapp1").withFallback(config))
  3. val app2 = ActorSystem("MyApp2", config.getConfig("myapp2").withOnlyPath("akka").withFallback(config))

These two samples demonstrate different variations of the “lift-a-subtree” trick: in the first case, the configuration accessible from within the actor system is this

  1. akka.loglevel = WARNING
  2. my.own.setting = 43
  3. my.other.setting = "hello"
  4. // plus myapp1 and myapp2 subtrees

while in the second one, only the “akka” subtree is lifted, with the following result:

  1. akka.loglevel = ERROR
  2. my.own.setting = 42
  3. my.other.setting = "hello"
  4. // plus myapp1 and myapp2 subtrees

Note

The configuration library is really powerful, explaining all features exceeds the scope affordable here. In particular not covered are how to include other configuration files within other files (see a small example at Including files) and copying parts of the configuration tree by way of path substitutions.

You may also specify and parse the configuration programmatically in other ways when instantiating the ActorSystem.

  1. import akka.actor.ActorSystem
  2. import com.typesafe.config.ConfigFactory
  3. val customConf = ConfigFactory.parseString("""
  4. akka.actor.deployment {
  5. /my-service {
  6. router = round-robin
  7. nr-of-instances = 3
  8. }
  9. }
  10. """)
  11. // ConfigFactory.load sandwiches customConfig between default reference
  12. // config and default overrides, and then resolves it.
  13. val system = ActorSystem("MySystem", ConfigFactory.load(customConf))

Listing of the Reference Configuration

Each Akka module has a reference configuration file with the default values.

akka-actor

  1. ####################################
  2. # Akka Actor Reference Config File #
  3. ####################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. akka {
  9. # Akka version, checked against the runtime version of Akka.
  10. version = "2.0.5"
  11.  
  12. # Home directory of Akka, modules in the deploy directory will be loaded
  13. home = ""
  14.  
  15. # Event handlers to register at boot time (Logging$DefaultLogger logs to STDOUT)
  16. event-handlers = ["akka.event.Logging$DefaultLogger"]
  17.  
  18. # Event handlers are created and registered synchronously during ActorSystem
  19. # start-up, and since they are actors, this timeout is used to bound the
  20. # waiting time
  21. event-handler-startup-timeout = 5s
  22.  
  23. # Log level used by the configured loggers (see "event-handlers") as soon
  24. # as they have been started; before that, see "stdout-loglevel"
  25. # Options: ERROR, WARNING, INFO, DEBUG
  26. loglevel = "INFO"
  27.  
  28. # Log level for the very basic logger activated during AkkaApplication startup
  29. # Options: ERROR, WARNING, INFO, DEBUG
  30. stdout-loglevel = "WARNING"
  31.  
  32. # Log the complete configuration at INFO level when the actor system is started.
  33. # This is useful when you are uncertain of what configuration is used.
  34. log-config-on-start = off
  35.  
  36. # List FQCN of extensions which shall be loaded at actor system startup.
  37. # Should be on the format: 'extensions = ["foo", "bar"]' etc.
  38. # See the Akka Documentation for more info about Extensions
  39. extensions = []
  40.  
  41. # Toggles whether the threads created by this ActorSystem should be daemons or not
  42. daemonic = off
  43.  
  44. # JVM shutdown, System.exit(-1), in case of a fatal error, such as OutOfMemoryError
  45. jvm-exit-on-fatal-error = on
  46.  
  47. actor {
  48.  
  49. provider = "akka.actor.LocalActorRefProvider"
  50.  
  51. # Timeout for ActorSystem.actorOf
  52. creation-timeout = 20s
  53.  
  54. # frequency with which stopping actors are prodded in case they had to be
  55. # removed from their parents
  56. reaper-interval = 5s
  57.  
  58. # Serializes and deserializes (non-primitive) messages to ensure immutability,
  59. # this is only intended for testing.
  60. serialize-messages = off
  61.  
  62. # Serializes and deserializes creators (in Props) to ensure that they can be sent over the network,
  63. # this is only intended for testing.
  64. serialize-creators = off
  65.  
  66. typed {
  67. # Default timeout for typed actor methods with non-void return type
  68. timeout = 5s
  69. }
  70.  
  71. deployment {
  72.  
  73. # deployment id pattern - on the format: /parent/child etc.
  74. default {
  75.  
  76. # routing (load-balance) scheme to use
  77. # available: "from-code", "round-robin", "random", "smallest-mailbox", "scatter-gather", "broadcast"
  78. # or: Fully qualified class name of the router class.
  79. # The router class must extend akka.routing.CustomRouterConfig and and have constructor
  80. # with com.typesafe.config.Config parameter.
  81. # default is "from-code";
  82. # Whether or not an actor is transformed to a Router is decided in code only (Props.withRouter).
  83. # The type of router can be overridden in the configuration; specifying "from-code" means
  84. # that the values specified in the code shall be used.
  85. # In case of routing, the actors to be routed to can be specified
  86. # in several ways:
  87. # - nr-of-instances: will create that many children
  88. # - routees.paths: will look the paths up using actorFor and route to
  89. # them, i.e. will not create children
  90. # - resizer: dynamically resizable number of routees as specified in resizer below
  91. router = "from-code"
  92.  
  93. # number of children to create in case of a non-direct router; this setting
  94. # is ignored if routees.paths is given
  95. nr-of-instances = 1
  96.  
  97. # within is the timeout used for routers containing future calls
  98. within = 5 seconds
  99.  
  100. routees {
  101. # Alternatively to giving nr-of-instances you can specify the full
  102. # paths of those actors which should be routed to. This setting takes
  103. # precedence over nr-of-instances
  104. paths = []
  105. }
  106.  
  107. # Routers with dynamically resizable number of routees; this feature is enabled
  108. # by including (parts of) this section in the deployment
  109. resizer {
  110.  
  111. # The fewest number of routees the router should ever have.
  112. lower-bound = 1
  113.  
  114. # The most number of routees the router should ever have.
  115. # Must be greater than or equal to lower-bound.
  116. upper-bound = 10
  117.  
  118. # Threshold to evaluate if routee is considered to be busy (under pressure).
  119. # Implementation depends on this value (default is 1).
  120. # 0: number of routees currently processing a message.
  121. # 1: number of routees currently processing a message has
  122. # some messages in mailbox.
  123. # > 1: number of routees with at least the configured pressure-threshold
  124. # messages in their mailbox. Note that estimating mailbox size of
  125. # default UnboundedMailbox is O(N) operation.
  126. pressure-threshold = 1
  127.  
  128. # Percentage to increase capacity whenever all routees are busy.
  129. # For example, 0.2 would increase 20% (rounded up), i.e. if current
  130. # capacity is 6 it will request an increase of 2 more routees.
  131. rampup-rate = 0.2
  132.  
  133. # Minimum fraction of busy routees before backing off.
  134. # For example, if this is 0.3, then we'll remove some routees only when
  135. # less than 30% of routees are busy, i.e. if current capacity is 10 and
  136. # 3 are busy then the capacity is unchanged, but if 2 or less are busy
  137. # the capacity is decreased.
  138. # Use 0.0 or negative to avoid removal of routees.
  139. backoff-threshold = 0.3
  140.  
  141. # Fraction of routees to be removed when the resizer reaches the
  142. # backoffThreshold.
  143. # For example, 0.1 would decrease 10% (rounded up), i.e. if current
  144. # capacity is 9 it will request an decrease of 1 routee.
  145. backoff-rate = 0.1
  146.  
  147. # When the resizer reduce the capacity the abandoned routee actors are stopped
  148. # with PoisonPill after this delay. The reason for the delay is to give concurrent
  149. # messages a chance to be placed in mailbox before sending PoisonPill.
  150. # Use 0s to skip delay.
  151. stop-delay = 1s
  152.  
  153. # Number of messages between resize operation.
  154. # Use 1 to resize before each message.
  155. messages-per-resize = 10
  156. }
  157. }
  158. }
  159.  
  160. default-dispatcher {
  161. # Must be one of the following
  162. # Dispatcher, (BalancingDispatcher, only valid when all actors using it are of
  163. # the same type), PinnedDispatcher, or a FQCN to a class inheriting
  164. # MessageDispatcherConfigurator with a constructor with
  165. # com.typesafe.config.Config parameter and akka.dispatch.DispatcherPrerequisites
  166. # parameters.
  167. # PinnedDispatcher must be used toghether with executor=thread-pool-executor.
  168. type = "Dispatcher"
  169.  
  170. # Which kind of ExecutorService to use for this dispatcher
  171. # Valid options:
  172. # "fork-join-executor" requires a "fork-join-executor" section
  173. # "thread-pool-executor" requires a "thread-pool-executor" section
  174. # or
  175. # A FQCN of a class extending ExecutorServiceConfigurator
  176. executor = "fork-join-executor"
  177.  
  178. # This will be used if you have set "executor = "fork-join-executor""
  179. fork-join-executor {
  180. # Min number of threads to cap factor-based parallelism number to
  181. parallelism-min = 8
  182.  
  183. # Parallelism (threads) ... ceil(available processors * factor)
  184. parallelism-factor = 3.0
  185.  
  186. # Max number of threads to cap factor-based parallelism number to
  187. parallelism-max = 64
  188. }
  189.  
  190. # This will be used if you have set "executor = "thread-pool-executor""
  191. thread-pool-executor {
  192. # Keep alive time for threads
  193. keep-alive-time = 60s
  194.  
  195. # Min number of threads to cap factor-based core number to
  196. core-pool-size-min = 8
  197.  
  198. # No of core threads ... ceil(available processors * factor)
  199. core-pool-size-factor = 3.0
  200.  
  201. # Max number of threads to cap factor-based number to
  202. core-pool-size-max = 64
  203.  
  204. # Hint: max-pool-size is only used for bounded task queues
  205. # minimum number of threads to cap factor-based max number to
  206. max-pool-size-min = 8
  207.  
  208. # Max no of threads ... ceil(available processors * factor)
  209. max-pool-size-factor = 3.0
  210.  
  211. # Max number of threads to cap factor-based max number to
  212. max-pool-size-max = 64
  213.  
  214. # Specifies the bounded capacity of the task queue (< 1 == unbounded)
  215. task-queue-size = -1
  216.  
  217. # Specifies which type of task queue will be used, can be "array" or
  218. # "linked" (default)
  219. task-queue-type = "linked"
  220.  
  221. # Allow core threads to time out
  222. allow-core-timeout = on
  223. }
  224.  
  225. # How long time the dispatcher will wait for new actors until it shuts down
  226. shutdown-timeout = 1s
  227.  
  228. # Throughput defines the number of messages that are processed in a batch
  229. # before the thread is returned to the pool. Set to 1 for as fair as possible.
  230. throughput = 5
  231.  
  232. # Throughput deadline for Dispatcher, set to 0 or negative for no deadline
  233. throughput-deadline-time = 0ms
  234.  
  235. # If negative (or zero) then an unbounded mailbox is used (default)
  236. # If positive then a bounded mailbox is used and the capacity is set using the
  237. # property
  238. # NOTE: setting a mailbox to 'blocking' can be a bit dangerous, could lead to
  239. # deadlock, use with care
  240. # The following mailbox-push-timeout-time is only used for type=Dispatcher and
  241. # only if mailbox-capacity > 0
  242. mailbox-capacity = -1
  243.  
  244. # Specifies the timeout to add a new message to a mailbox that is full -
  245. # negative number means infinite timeout. It is only used for type=Dispatcher
  246. # and only if mailbox-capacity > 0
  247. mailbox-push-timeout-time = 10s
  248.  
  249. # FQCN of the MailboxType, if not specified the default bounded or unbounded
  250. # mailbox is used. The Class of the FQCN must have a constructor with
  251. # (akka.actor.ActorSystem.Settings, com.typesafe.config.Config) parameters.
  252. mailbox-type = ""
  253.  
  254. # For BalancingDispatcher: If the balancing dispatcher should attempt to
  255. # schedule idle actors using the same dispatcher when a message comes in,
  256. # and the dispatchers ExecutorService is not fully busy already.
  257. attempt-teamwork = on
  258.  
  259. # For Actor with Stash: The default capacity of the stash.
  260. # If negative (or zero) then an unbounded stash is used (default)
  261. # If positive then a bounded stash is used and the capacity is set using the
  262. # property
  263. stash-capacity = -1
  264. }
  265.  
  266. debug {
  267. # enable function of Actor.loggable(), which is to log any received message at
  268. # DEBUG level, see the “Testing Actor Systems” section of the Akka Documentation
  269. # at https://akka.io/docs
  270. receive = off
  271.  
  272. # enable DEBUG logging of all AutoReceiveMessages (Kill, PoisonPill and the like)
  273. autoreceive = off
  274.  
  275. # enable DEBUG logging of actor lifecycle changes
  276. lifecycle = off
  277.  
  278. # enable DEBUG logging of all LoggingFSMs for events, transitions and timers
  279. fsm = off
  280.  
  281. # enable DEBUG logging of subscription changes on the eventStream
  282. event-stream = off
  283. }
  284.  
  285. # Entries for pluggable serializers and their bindings.
  286. serializers {
  287. java = "akka.serialization.JavaSerializer"
  288. }
  289.  
  290. # Class to Serializer binding. You only need to specify the name of an interface
  291. # or abstract base class of the messages. In case of ambiguity it is using the
  292. # most specific configured class, or giving a warning and choosing the “first” one.
  293. #
  294. # To disable one of the default serializers, assign its class to "none", like
  295. # "java.io.Serializable" = none
  296. serialization-bindings {
  297. "java.io.Serializable" = java
  298. }
  299. }
  300.  
  301. # Used to set the behavior of the scheduler.
  302. # Changing the default values may change the system behavior drastically so make sure
  303. # you know what you're doing! See the Scheduler section of the Akka documentation for more details.
  304. scheduler {
  305. # The HashedWheelTimer (HWT) implementation from Netty is used as the default scheduler
  306. # in the system.
  307. # HWT does not execute the scheduled tasks on exact time.
  308. # It will, on every tick, check if there are any tasks behind the schedule and execute them.
  309. # You can increase or decrease the accuracy of the execution timing by specifying smaller
  310. # or larger tick duration.
  311. # If you are scheduling a lot of tasks you should consider increasing the ticks per wheel.
  312. # For more information see: http://www.jboss.org/netty/
  313. tick-duration = 100ms
  314. ticks-per-wheel = 512
  315. }
  316. }

akka-remote

  1. #####################################
  2. # Akka Remote Reference Config File #
  3. #####################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. # comments about akka.actor settings left out where they are already in akka-
  9. # actor.jar, because otherwise they would be repeated in config rendering.
  10.  
  11. akka {
  12.  
  13. actor {
  14.  
  15. serializers {
  16. proto = "akka.serialization.ProtobufSerializer"
  17. }
  18.  
  19.  
  20. serialization-bindings {
  21. # Since com.google.protobuf.Message does not extend Serializable but GeneratedMessage
  22. # does, need to use the more specific one here in order to avoid ambiguity
  23. "com.google.protobuf.GeneratedMessage" = proto
  24. }
  25.  
  26. deployment {
  27.  
  28. default {
  29.  
  30. # if this is set to a valid remote address, the named actor will be deployed
  31. # at that node e.g. "akka://sys@host:port"
  32. remote = ""
  33.  
  34. target {
  35.  
  36. # A list of hostnames and ports for instantiating the children of a
  37. # non-direct router
  38. # The format should be on "akka://sys@host:port", where:
  39. # - sys is the remote actor system name
  40. # - hostname can be either hostname or IP address the remote actor
  41. # should connect to
  42. # - port should be the port for the remote server on the other node
  43. # The number of actor instances to be spawned is still taken from the
  44. # nr-of-instances setting as for local routers; the instances will be
  45. # distributed round-robin among the given nodes.
  46. nodes = []
  47.  
  48. }
  49. }
  50. }
  51. }
  52.  
  53. remote {
  54.  
  55. # Which implementation of akka.remote.RemoteTransport to use
  56. # default is a TCP-based remote transport based on Netty
  57. transport = "akka.remote.netty.NettyRemoteTransport"
  58.  
  59. # Enable untrusted mode for full security of server managed actors, allows
  60. # untrusted clients to connect.
  61. untrusted-mode = off
  62.  
  63. # Timeout for ACK of cluster operations, like checking actor out etc.
  64. remote-daemon-ack-timeout = 30s
  65.  
  66. # If this is "on", Akka will log all inbound messages at DEBUG level, if off then they are not logged
  67. log-received-messages = off
  68.  
  69. # If this is "on", Akka will log all outbound messages at DEBUG level, if off then they are not logged
  70. log-sent-messages = off
  71.  
  72. # If this is "on", Akka will log all RemoteLifeCycleEvents at the level defined for each, if off then they are not logged
  73. log-remote-lifecycle-events = off
  74.  
  75. # Each property is annotated with (I) or (O) or (I&O), where I stands for “inbound” and O for “outbound” connections.
  76. # The NettyRemoteTransport always starts the server role to allow inbound connections, and it starts
  77. # active client connections whenever sending to a destination which is not yet connected; if configured
  78. # it reuses inbound connections for replies, which is called a passive client connection (i.e. from server
  79. # to client).
  80. netty {
  81.  
  82. # (O) In case of increased latency / overflow how long should we wait (blocking the sender)
  83. # until we deem the send to be cancelled?
  84. # 0 means "never backoff", any positive number will indicate time to block at most.
  85. backoff-timeout = 0ms
  86.  
  87. # (I&O) Generate your own with '$AKKA_HOME/scripts/generate_config_with_secure_cookie.sh'
  88. # or using 'akka.util.Crypt.generateSecureCookie'
  89. secure-cookie = ""
  90.  
  91. # (I) Should the remote server require that its peers share the same secure-cookie
  92. # (defined in the 'remote' section)?
  93. require-cookie = off
  94.  
  95. # (I) Reuse inbound connections for outbound messages
  96. use-passive-connections = on
  97.  
  98. # (I) The hostname or ip to bind the remoting to,
  99. # InetAddress.getLocalHost.getHostAddress is used if empty
  100. hostname = ""
  101.  
  102. # (I) The default remote server port clients should connect to.
  103. # Default is 2552 (AKKA), use 0 if you want a random available port
  104. # This port needs to be unique for each actor system on the same machine.
  105. port = 2552
  106.  
  107. # (O) The address of a local network interface (IP Address) to bind to when creating
  108. # outbound connections. Set to "" or "auto" for automatic selection of local address.
  109. outbound-local-address = "auto"
  110.  
  111. # (I&O) Increase this if you want to be able to send messages with large payloads
  112. message-frame-size = 1 MiB
  113.  
  114. # (O) Timeout duration
  115. connection-timeout = 120s
  116.  
  117. # (I) Sets the size of the connection backlog
  118. backlog = 4096
  119.  
  120. # (I) Length in akka.time-unit how long core threads will be kept alive if idling
  121. execution-pool-keepalive = 60s
  122.  
  123. # (I) Size of the core pool of the remote execution unit
  124. execution-pool-size = 4
  125.  
  126. # (I) Maximum channel size, 0 for off
  127. max-channel-memory-size = 0b
  128.  
  129. # (I) Maximum total size of all channels, 0 for off
  130. max-total-memory-size = 0b
  131.  
  132. # (O) Time between reconnect attempts for active clients
  133. reconnect-delay = 5s
  134.  
  135. # (O) Read inactivity period (lowest resolution is seconds)
  136. # after which active client connection is shutdown;
  137. # will be re-established in case of new communication requests.
  138. # A value of 0 will turn this feature off
  139. read-timeout = 0s
  140.  
  141. # (O) Write inactivity period (lowest resolution is seconds)
  142. # after which a heartbeat is sent across the wire.
  143. # A value of 0 will turn this feature off
  144. write-timeout = 10s
  145.  
  146. # (O) Inactivity period of both reads and writes (lowest resolution is seconds)
  147. # after which active client connection is shutdown;
  148. # will be re-established in case of new communication requests
  149. # A value of 0 will turn this feature off
  150. all-timeout = 0s
  151.  
  152. # (O) Maximum time window that a client should try to reconnect for
  153. reconnection-time-window = 600s
  154.  
  155. # (I&O) Used to configure the number of I/O worker threads on server sockets
  156. server-socket-worker-pool {
  157. # Min number of threads to cap factor-based number to
  158. pool-size-min = 2
  159.  
  160. # The pool size factor is used to determine thread pool size
  161. # using the following formula: ceil(available processors * factor).
  162. # Resulting size is then bounded by the pool-size-min and
  163. # pool-size-max values.
  164. pool-size-factor = 2.0
  165.  
  166. # Max number of threads to cap factor-based number to
  167. pool-size-max = 128
  168. }
  169.  
  170. # (I&O) Used to configure the number of I/O worker threads on client sockets
  171. client-socket-worker-pool {
  172. # Min number of threads to cap factor-based number to
  173. pool-size-min = 2
  174.  
  175. # The pool size factor is used to determine thread pool size
  176. # using the following formula: ceil(available processors * factor).
  177. # Resulting size is then bounded by the pool-size-min and
  178. # pool-size-max values.
  179. pool-size-factor = 2.0
  180.  
  181. # Max number of threads to cap factor-based number to
  182. pool-size-max = 128
  183. }
  184. }
  185.  
  186. # The dispatcher used for the system actor "network-event-sender"
  187. network-event-sender-dispatcher {
  188. executor = thread-pool-executor
  189. type = PinnedDispatcher
  190. }
  191. }
  192. }

akka-testkit

  1. ######################################
  2. # Akka Testkit Reference Config File #
  3. ######################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. akka {
  9. test {
  10. # factor by which to scale timeouts during tests, e.g. to account for shared
  11. # build system load
  12. timefactor = 1.0
  13.  
  14. # duration of EventFilter.intercept waits after the block is finished until
  15. # all required messages are received
  16. filter-leeway = 3s
  17.  
  18. # duration to wait in expectMsg and friends outside of within() block by default
  19. single-expect-default = 3s
  20.  
  21. # The timeout that is added as an implicit by DefaultTimeout trait
  22. default-timeout = 5s
  23.  
  24. calling-thread-dispatcher {
  25. type = akka.testkit.CallingThreadDispatcherConfigurator
  26. }
  27. }
  28. }

akka-transactor

  1. #########################################
  2. # Akka Transactor Reference Config File #
  3. #########################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. akka {
  9. transactor {
  10. # The timeout used for coordinated transactions across actors
  11. coordinated-timeout = 5s
  12. }
  13. }

akka-agent

  1. ####################################
  2. # Akka Agent Reference Config File #
  3. ####################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. akka {
  9. agent {
  10.  
  11. # The dispatcher used for agent-send-off actor
  12. send-off-dispatcher {
  13. executor = thread-pool-executor
  14. type = PinnedDispatcher
  15. }
  16.  
  17. # The dispatcher used for agent-alter-off actor
  18. alter-off-dispatcher {
  19. executor = thread-pool-executor
  20. type = PinnedDispatcher
  21. }
  22. }
  23. }

akka-zeromq

  1. #####################################
  2. # Akka ZeroMQ Reference Config File #
  3. #####################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. akka {
  9.  
  10. zeromq {
  11.  
  12. # The default timeout for a poll on the actual zeromq socket.
  13. poll-timeout = 100ms
  14.  
  15. # Timeout for creating a new socket
  16. new-socket-timeout = 5s
  17.  
  18. socket-dispatcher {
  19. # A zeromq socket needs to be pinned to the thread that created it.
  20. # Changing this value results in weird errors and race conditions within zeromq
  21. executor = thread-pool-executor
  22. type = "PinnedDispatcher"
  23. }
  24. }
  25. }

akka-beanstalk-mailbox

  1. ##################################################
  2. # Akka Beanstalk Mailboxes Reference Config File #
  3. ##################################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7. #
  8. # for more information see <https://github.com/kr/beanstalkd/blob/v1.3/doc/protocol.txt>
  9.  
  10. akka {
  11. actor {
  12. mailbox {
  13. beanstalk {
  14. # hostname to connect to
  15. hostname = "127.0.0.1"
  16. # port to connect to
  17. port = 11300
  18. # wait period in case of a connection failure before reconnect
  19. reconnect-window = 5s
  20. # integer number of seconds to wait before putting the job in
  21. # the ready queue. The job will be in the "delayed" state during this time.
  22. message-submit-delay = 0s
  23. # time to run -- is an integer number of seconds to allow a worker
  24. # to run this job. This time is counted from the moment a worker reserves
  25. # this job. If the worker does not delete, release, or bury the job within
  26. # <ttr> seconds, the job will time out and the server will release the job.
  27. message-time-to-live = 120s
  28. }
  29. }
  30. }
  31.  
  32. }

akka-file-mailbox

  1. #############################################
  2. # Akka File Mailboxes Reference Config File #
  3. #############################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7. #
  8. # For more information see <https://github.com/robey/kestrel/>
  9.  
  10. akka {
  11. actor {
  12. mailbox {
  13. file-based {
  14. # directory below which this queue resides
  15. directory-path = "./_mb"
  16. # attempting to add an item after the queue reaches this size (in items) will fail.
  17. max-items = 2147483647
  18. # attempting to add an item after the queue reaches this size (in bytes) will fail.
  19. max-size = 2147483647 bytes
  20. # attempting to add an item larger than this size (in bytes) will fail.
  21. max-item-size = 2147483647 bytes
  22. # maximum expiration time for this queue (seconds).
  23. max-age = 0s
  24. # maximum journal size before the journal should be rotated.
  25. max-journal-size = 16 MiB
  26. # maximum size of a queue before it drops into read-behind mode.
  27. max-memory-size = 128 MiB
  28. # maximum overflow (multiplier) of a journal file before we re-create it.
  29. max-journal-overflow = 10
  30. # absolute maximum size of a journal file until we rebuild it, no matter what.
  31. max-journal-size-absolute = 9223372036854775807 bytes
  32. # whether to drop older items (instead of newer) when the queue is full
  33. discard-old-when-full = on
  34. # whether to keep a journal file at all
  35. keep-journal = on
  36. # whether to sync the journal after each transaction
  37. sync-journal = off
  38. }
  39. }
  40. }
  41. }

akka-mongo-mailbox

  1. ################################################
  2. # Akka MongoDB Mailboxes Reference Config File #
  3. ################################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7.  
  8. akka {
  9. actor {
  10. mailbox {
  11. mongodb {
  12.  
  13. # Any specified collection name will be used as a prefix for
  14. # collections that use durable mongo mailboxes.
  15. # Follow Mongo URI Spec - http://www.mongodb.org/display/DOCS/Connections
  16. uri = "mongodb://localhost/akka.mailbox"
  17.  
  18. # Configurable timeouts for certain ops
  19. timeout {
  20. # time to wait for a read to succeed before timing out the future
  21. read = 3000ms
  22. # time to wait for a write to succeed before timing out the future
  23. write = 3000ms
  24. }
  25. }
  26. }
  27. }
  28. }

akka-redis-mailbox

  1. ##############################################
  2. # Akka Redis Mailboxes Reference Config File #
  3. ##############################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7. #
  8. # for more information see <http://redis.io/>
  9.  
  10. akka {
  11. actor {
  12. mailbox {
  13. redis {
  14. # hostname of where the redis queue resides
  15. hostname = "127.0.0.1"
  16. # port at which the redis queue resides
  17. port = 6379
  18. }
  19. }
  20. }
  21. }

akka-zookeeper-mailbox

  1. ##################################################
  2. # Akka ZooKepper Mailboxes Reference Config File #
  3. ##################################################
  4.  
  5. # This is the reference config file that contains all the default settings.
  6. # Make your edits/overrides in your application.conf.
  7. #
  8. # For more information see <http://wiki.apache.org/hadoop/ZooKeeper>
  9.  
  10. akka {
  11. actor {
  12. mailbox {
  13. zookeeper {
  14. # host and port to connect to ZooKeeper
  15. server-addresses = "127.0.0.1:2181"
  16. # timeout after which an unreachable client is considered dead and its session is closed
  17. session-timeout = 60s
  18. # maximum wait period while connecting to ZooKeeper service
  19. connection-timeout = 60s
  20. }
  21. }
  22. }
  23. }

Custom application.conf

A custom application.conf might look like this:

  1. # In this file you can override any option defined in the reference files.
  2. # Copy in parts of the reference files and modify as you please.
  3.  
  4. akka {
  5.  
  6. # Event handlers to register at boot time (Logging$DefaultLogger logs to STDOUT)
  7. event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
  8.  
  9. # Log level used by the configured loggers (see "event-handlers") as soon
  10. # as they have been started; before that, see "stdout-loglevel"
  11. # Options: ERROR, WARNING, INFO, DEBUG
  12. loglevel = DEBUG
  13.  
  14. # Log level for the very basic logger activated during AkkaApplication startup
  15. # Options: ERROR, WARNING, INFO, DEBUG
  16. stdout-loglevel = DEBUG
  17.  
  18. actor {
  19. default-dispatcher {
  20. # Throughput for default Dispatcher, set to 1 for as fair as possible
  21. throughput = 10
  22. }
  23. }
  24.  
  25. remote {
  26. server {
  27. # The port clients should connect to. Default is 2552 (AKKA)
  28. port = 2562
  29. }
  30. }
  31. }

Including files

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.

Specifying system property with -Dconfig.resource=/dev.conf will load the dev.conf file, which includes the application.conf

dev.conf:

  1. include "application"
  2.  
  3. akka {
  4. loglevel = "DEBUG"
  5. }

More advanced include and substitution mechanisms are explained in the HOCON specification.

Logging of Configuration

If the system or config property akka.log-config-on-start 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.

If in doubt, you can also easily and nicely inspect configuration objects before or after using them to construct an actor system:

  1. Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
  2. Type in expressions to have them evaluated.
  3. Type :help for more information.
  4.  
  5. scala> import com.typesafe.config._
  6. import com.typesafe.config._
  7.  
  8. scala> ConfigFactory.parseString("a.b=12")
  9. res0: com.typesafe.config.Config = Config(SimpleConfigObject({"a" : {"b" : 12}}))
  10.  
  11. scala> res0.root.render
  12. res1: java.lang.String =
  13. {
  14. # String: 1
  15. "a" : {
  16. # String: 1
  17. "b" : 12
  18. }
  19. }

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:

  1. final ActorSystem system = ActorSystem.create();
  2. println(system.settings());
  3. // this is a shortcut for system.settings().config().root().render()

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 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 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 NullPointerException from strange places: this is simply not supported.

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: