2017-08-14 42 views
0

我正在使用Play 2.3.7,我需要使用控制器內部的Actor。下面的代碼工作正常無法查找自定義調度程序

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) 

現在我做如下改變我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 
     } 
     } 
    } 
    } 
} 

而現在,我的代碼更改爲

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) 

我得到一個異常有消息[foo-dispatcher] not configured

回答

1

參考的完整路徑:

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

如果你想使用system.dispatchers.lookup("foo-dispatcher"),定義foo-dispatcherplay命名空間之外:

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 
    } 
}