Support config of custom router. See #1623
This commit is contained in:
parent
1f3926fa0e
commit
8d10d44929
7 changed files with 69 additions and 13 deletions
|
|
@ -13,6 +13,7 @@ import akka.util.Duration
|
|||
import akka.config.ConfigurationException
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import com.typesafe.config.Config
|
||||
|
||||
object RoutingSpec {
|
||||
|
||||
|
|
@ -22,6 +23,10 @@ object RoutingSpec {
|
|||
router = round-robin
|
||||
nr-of-instances = 3
|
||||
}
|
||||
/myrouter {
|
||||
router = "akka.routing.RoutingSpec$MyRouter"
|
||||
foo = bar
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
|
@ -38,6 +43,18 @@ object RoutingSpec {
|
|||
}
|
||||
}
|
||||
|
||||
class MyRouter(config: Config) extends RouterConfig {
|
||||
val foo = config.getString("foo")
|
||||
def createRoute(routeeProps: Props, actorContext: ActorContext): Route = {
|
||||
val routees = IndexedSeq(actorContext.actorOf(Props[Echo]))
|
||||
registerRoutees(actorContext, routees)
|
||||
|
||||
{
|
||||
case (sender, message) ⇒ Nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
||||
|
|
@ -465,6 +482,10 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with
|
|||
sys.shutdown()
|
||||
}
|
||||
}
|
||||
"support custom router" in {
|
||||
val myrouter = system.actorOf(Props().withRouter(FromConfig), "myrouter")
|
||||
myrouter.isTerminated must be(false)
|
||||
}
|
||||
}
|
||||
|
||||
"custom router" must {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue