Akka 喷射http客户端和数千个请求

Akka 喷射http客户端和数千个请求,akka,spray-client,Akka,Spray Client,我想以控制发送到服务器的最大请求数的方式配置spray http客户端。我需要这个,因为我发送请求的服务器会阻止我发送超过2个请求。我明白了 akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://smallTasks/user/IO-HTTP#151444590]] after [15000 ms] akka.pattern.AskTimeoutException: Ask timed out on [Actor[akk

我想以控制发送到服务器的最大请求数的方式配置spray http客户端。我需要这个,因为我发送请求的服务器会阻止我发送超过2个请求。我明白了

akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://smallTasks/user/IO-HTTP#151444590]] after [15000 ms]
akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://smallTasks/user/IO-HTTP#151444590]] after [15000 ms]
akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://smallTasks/user/IO-HTTP#151444590]] after [15000 ms]
akka.pattern.AskTimeoutException: Ask timed out on 
我需要发送数千个请求,但在收到约100个请求的响应后,我被阻止

我有这个方法:

  implicit val system = ActorSystem("smallTasks")
  implicit val timeout = new Timeout(15.seconds)

  import system.dispatcher

  def doHttpRequest(url: String): Future[HttpResponse] = {
    (IO(Http) ? HttpRequest(GET, Uri(url))).mapTo[HttpResponse]
  }
在这里,我捕获响应并在失败时重试(递归):

如何正确地做到这一点?我可能需要以某种方式配置akka dispatcher?

您可以使用并编写个人管道

val pipeline: Future[SendReceive] =
      for (
        Http.HostConnectorInfo(connector, _) <-
          IO(Http) ? Http.HostConnectorSetup("www.spray.io", port = 80)
      ) yield sendReceive(connector)

    val request = Get("/segment1/segment2/...")
    val responseFuture: Future[HttpResponse] = pipeline.flatMap(_(request))
转化

import spray.json._
response.entity.asString.parseJson.convertTo[T]
查证

Try(response.entity.asString.parseJson).isSuccess

括号太多。在scala中,您可以将其写得更短

如果已达到最大并发连接数,您想做什么?拒绝请求?等待给定的超时?我需要收集每个型号的信息,所以如果请求失败,我想用超时重试失败的请求。我已经这么做了(参见Thread.sleep(200))。它可以在10-15秒内正常工作,在这之后,我在控制台中收到很多Akka ask超时异常。我想这是因为我有10000个模型,它们都是同时发布的。我正在寻找一种方法,强制http客户端每次只发送2或3个请求,而在旧请求没有响应时不发送其他请求
import spray.json._
response.entity.asString.parseJson.convertTo[T]
Try(response.entity.asString.parseJson).isSuccess