【问题标题】:Not able to lookup a custom dispatcher无法查找自定义调度程序
【发布时间】:2017-08-14 22:38:21
【问题描述】:

我使用的是 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 的异常

【问题讨论】:

    标签: scala playframework playframework-2.3


    【解决方案1】:

    参考完整路径:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多