diff --git a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala index 711bf04371..419d367d19 100644 --- a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala @@ -15,6 +15,15 @@ import com.typesafe.config.ConfigFactory object RoutingSpec { + val config = """ + akka.actor.deployment { + /router1 { + router = round-robin + nr-of-instances = 3 + } + } + """ + class TestActor extends Actor { def receive = { case _ ⇒ @@ -31,7 +40,7 @@ object RoutingSpec { } @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender { +class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with ImplicitSender { import akka.routing.RoutingSpec._ @@ -87,6 +96,18 @@ class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender { Await.ready(doneLatch, 1 seconds) } + "use configured nr-of-instances when FromConfig" in { + val router = system.actorOf(Props[TestActor].withRouter(FromConfig), "router1") + Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(3) + system.stop(router) + } + + "use configured nr-of-instances when router is specified" in { + val router = system.actorOf(Props[TestActor].withRouter(RoundRobinRouter(nrOfInstances = 2)), "router1") + Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(3) + system.stop(router) + } + } "no router" must { diff --git a/akka-actor/src/main/resources/reference.conf b/akka-actor/src/main/resources/reference.conf index 5b74a24c8f..e016810d2c 100644 --- a/akka-actor/src/main/resources/reference.conf +++ b/akka-actor/src/main/resources/reference.conf @@ -76,6 +76,7 @@ akka { # supplied in the source code (overridable using create-as below) # - routees.paths: will look the paths up using actorFor and route to # them, i.e. will not create children + # - resizer: dynamically resizable number of routees as specified in resizer below router = "from-code" # number of children to create in case of a non-direct router; this setting diff --git a/akka-docs/java/routing.rst b/akka-docs/java/routing.rst index 3544c95a51..e80514a8fe 100644 --- a/akka-docs/java/routing.rst +++ b/akka-docs/java/routing.rst @@ -44,8 +44,9 @@ You can also give the router already created routees as in: When you create a router programatically you define the number of routees *or* you pass already created routees to it. If you send both parameters to the router *only* the latter will be used, i.e. ``nrOfInstances`` is disregarded. -*It is also worth pointing out that if you define the number of routees in the configuration file then this -value will be used instead of any programmatically sent parameters.* +*It is also worth pointing out that if you define the number of routees (``nr-of-instances`` or ``routees``) in +the configuration file then this value will be used instead of any programmatically sent parameters, but you must +also define the ``router`` property in the configuration.* Once you have the router actor it is just to send messages to it as you would to any actor: @@ -189,6 +190,9 @@ This is an example of how to programatically create a resizable router: .. includecode:: code/akka/docs/jrouting/RouterViaProgramExample.java#programmaticRoutingWithResizer +*It is also worth pointing out that if you define the ``router`` in the configuration file then this value +will be used instead of any programmatically sent parameters.* + Custom Router ^^^^^^^^^^^^^ diff --git a/akka-docs/scala/routing.rst b/akka-docs/scala/routing.rst index 1ba967f772..ad06b67b8b 100644 --- a/akka-docs/scala/routing.rst +++ b/akka-docs/scala/routing.rst @@ -44,8 +44,9 @@ You can also give the router already created routees as in: When you create a router programatically you define the number of routees *or* you pass already created routees to it. If you send both parameters to the router *only* the latter will be used, i.e. ``nrOfInstances`` is disregarded. -*It is also worth pointing out that if you define the number of routees in the configuration file then this -value will be used instead of any programmatically sent parameters.* +*It is also worth pointing out that if you define the number of routees (``nr-of-instances`` or ``routees``) in +the configuration file then this value will be used instead of any programmatically sent parameters, but you must +also define the ``router`` property in the configuration.* Once you have the router actor it is just to send messages to it as you would to any actor: @@ -190,6 +191,8 @@ This is an example of how to programatically create a resizable router: .. includecode:: code/akka/docs/routing/RouterViaProgramExample.scala#programmaticRoutingWithResizer +*It is also worth pointing out that if you define the ``router`` in the configuration file then this value +will be used instead of any programmatically sent parameters.* Custom Router ^^^^^^^^^^^^^