【问题标题】:AskTimeoutException: on spray-can server stopAskTimeoutException:喷雾罐服务器停止
【发布时间】:2014-06-18 14:12:31
【问题描述】:

我正在尝试使用以下代码停止 spray-can 网络服务器:

implicit val timeout = Timeout(10 seconds)
val future = ask(IO(Http)(system), Http.Unbind(10 second))
Await.result(future, Duration.Inf)

但不幸的是,我收到以下异常:

[错误] AskTimeoutException: : 超时 (AskSupport.scala:334) [错误] akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:334) [错误] akka.actor.Scheduler$$anon$11.run(Scheduler.scala:118) [错误] akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(Scheduler.scala:455) [错误] akka.actor.LightArrayRevolverScheduler$$anon$12.executeBucket$1(Scheduler.scala:407) [错误] akka.actor.LightArrayRevolverScheduler$$anon$12.nextTick(Scheduler.scala:411) [错误] akka.actor.LightArrayRevolverScheduler$$anon$12.run(Scheduler.scala:363)

我做错了什么?

【问题讨论】:

    标签: scala akka spray


    【解决方案1】:

    问题是您将Http.Unbind 消息发送给错误的actor(即IO 扩展的管理器actor - 在本例中为Http)。

    您必须将Http.Unbind 消息发送到HttpListener(这是使用Http.Bound 消息回复Http.Bind 消息的参与者)。以下示例将Http.Bind 发送给经理actor,将Http.Unbind 发送给HttpListener

    class TestActor extends Actor {
      override def preStart = {
        IO(Http) ! Http.Bind(self, interface = "localhost", port = 8080)
      }
      def receive = {
        case Http.Bound(_) => 
          println("bound")
          sender ! Http.Unbind(10 seconds)
        case Http.Unbound =>
          println("unbound")
          context.stop(self)
      }
    }
    

    更多信息可以在documentation 中找到关于启动和停止的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 2011-02-23
      相关资源
      最近更新 更多