Akka Http:超过配置的最大值
我使用下面的代码发布一些数据到服务器
def post(endpoint: String, entity: Strict) = {
Http().singleRequest(HttpRequest(uri = Notifier.notificationUrl + endpoint, method = HttpMethods.POST,
entity = entity)) onComplete {
case Success(response) => response match {
case HttpResponse(StatusCodes.OK, _, _, _) =>
log.info("communicated successfully with Server")
}
case Failure(response) =>
log.error("communicated failed with Server: {}", response)
}
}
当Notifier
actor收到如下消息时,每10 seconds
调用一次
case ecMonitorInformation: ECMonitorInformation =>
post("monitor", httpEntityFromJson(ecMonitorInformation.toJson))
问题?
我看到最初(大约5
请求去服务器),但它后来,我没有看到任何日志记录,服务器没有收到任何数据。 过了一会儿,在客户端,我看到以下
ERROR c.s.e.notification.Notifier - communicated failed with Server: java.lang.RuntimeException: Exceeded configured max-open-requests value of [32]
到底是怎么回事? 我如何解决这个问题?
我浏览了文档并尝试了以下内容
val connectionFlow: Flow[HttpRequest, HttpResponse,
Future[Http.OutgoingConnection]] =
Http().outgoingConnection(host = "localhost", port = 8080)
接着
def httpPost(uri: String, httpEntity:Strict) {
val responseFuture: Future[HttpResponse] =
Source.single(HttpRequest(uri = "/monitor", method = HttpMethods.POST, entity=httpEntity))
.via(connectionFlow)
.runWith(Sink.head)
responseFuture onComplete {
case Success(response) => log.info("Communicated with Server: {}", response)
case Failure(failure) => log.error("Communication failed with Server: {}", failure)
}
这对我有用
如果您要反复调用您的方法,则可能需要考虑使用以下所述的基于连接池的客户端方法之一:http://doc.akka.io/docs/akka-stream-and-http-experimental /1.0/scala/http/client-side/index.html
您还可以在akka-http客户端配置中设置连接池设置:http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/configuration.html#akka- HTTP核
搜索主机连接池。
您可以使用Source.queue
而不是Source.single
来提供缓冲和溢出策略。 请参阅https://stackoverflow.com/a/35115314/1699837上的更多详细信息