Akka Http:超过配置的 max-open-requests 值 [32]
Akka Http: Exceeded configured max-open-requests value of [32]
我post一些数据到服务器使用下面的代码
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)
}
}
每 10 seconds
当 Notifier
演员收到如下消息时调用此方法
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]
这是怎么回事?我该如何解决这个问题?
如果您要重复调用您的方法,您可能需要考虑使用此处所述的基于连接池的客户端方法之一:
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-core
搜索主机连接池。
我浏览了 docs 并尝试了以下
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)
}
这对我有用
您可以使用 Source.queue
而不是 Source.single
来提供缓冲和溢出策略。在
查看更多详细信息
您也可以通过提高 akka 的 max-open-requests
属性 默认情况下 32
来克服此错误。
要更改的 属性 将是:
akka.http.host-connection-pool.max-open-requests = 64
唯一需要注意的是,当客户端打开的并发连接数多于该参数的新值时,这将失败,在此示例中,如果打开的连接数超过 64
,您将得到相同的错误.
我post一些数据到服务器使用下面的代码
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)
}
}
每 10 seconds
当 Notifier
演员收到如下消息时调用此方法
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]
这是怎么回事?我该如何解决这个问题?
如果您要重复调用您的方法,您可能需要考虑使用此处所述的基于连接池的客户端方法之一: 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-core
搜索主机连接池。
我浏览了 docs 并尝试了以下
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)
}
这对我有用
您可以使用 Source.queue
而不是 Source.single
来提供缓冲和溢出策略。在
您也可以通过提高 akka 的 max-open-requests
属性 默认情况下 32
来克服此错误。
要更改的 属性 将是:
akka.http.host-connection-pool.max-open-requests = 64
唯一需要注意的是,当客户端打开的并发连接数多于该参数的新值时,这将失败,在此示例中,如果打开的连接数超过 64
,您将得到相同的错误.