2017-08-14 64 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 
    } 
} 
相关问题