2017-08-14 1 views
0

Ich benutze Play 2.3.7 und ich brauche Actors aus dem Controller. Der folgende Code funktioniert gutNicht in der Lage, einen benutzerdefinierten Dispatcher nachzuschlagen

implicit val system = ActorSystem() 
implicit val dispatcher = system.dispatcher 
val future = (IO(Http) ? Get(url).withHeaders(...).mapTo[HttpResponse] 
val result = Await.results(future, Duration.Inf) 

Jetzt habe ich folgende Änderung der Code meiner conf/application.conf

play { 
    akka { 
    actor { 
     default-dispatcher { 
     type = Dispatcher 
     executor = "thread-pool-executor" 
     thread-pool-executor { 
      fixed-pool-size = 128 
     } 
     } 
     foo-dispatcher { 
     type = Dispatcher 
     executor = "thread-pool-executor" 
     thread-pool-executor { 
      fixed-pool-size = 128 
     } 
     } 
    } 
    } 
} 

Und jetzt machen ändern

implicit val system = ActorSystem() 
implicit val dispatcher = system.dispatchers.lookup("foo-dispatcher") 
val future = (IO(Http) ? Get(url).withHeaders(...).mapTo[HttpResponse] 
val result = Await.results(future, Duration.Inf) 

Ich erhalte eine Ausnahme mit der Meldung [foo-dispatcher] not configured

Antwort

1

Referenz für den vollständigen Pfad:

implicit val dispatcher = system.dispatchers.lookup("play.akka.actor.foo-dispatcher") 

Wenn Sie system.dispatchers.lookup("foo-dispatcher") verwenden möchten, definieren foo-dispatcher außerhalb des play Namespace:

play { 
    akka { 
    actor { 
     default-dispatcher { 
     type = Dispatcher 
     executor = "thread-pool-executor" 
     thread-pool-executor { 
      fixed-pool-size = 128 
     } 
     } 
    } 
    } 
} 

foo-dispatcher { 
    type = Dispatcher 
    executor = "thread-pool-executor" 
    thread-pool-executor { 
    fixed-pool-size = 128 
    } 
}