无法查找自定义调度程序

时间:2017-08-14 22:38:22

标签: scala playframework playframework-2.3

我正在使用Play 2.3.7,我需要在控制器内部使用Actors。以下代码工作正常

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 个答案:

答案 0 :(得分:1)

参考完整路径:

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

如果您想使用system.dispatchers.lookup("foo-dispatcher"),请在foo-dispatcher命名空间之外定义play

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