Akka HTTP Error Response entity was not subscribed after 1 second

谁都会走 提交于 2021-02-08 05:41:35

问题


I am using Akka HTTP cachedHostConnectionPoolHttps pool to send requests as part of Akka Streams Flow:

  private val requestFlow: Flow[(HttpRequest, HelperClass), Either[Error, String], _] =
Http().cachedHostConnectionPoolHttps(BaseUrl).mapAsync(1) {
  case (Success(HttpResponse(_, _, entity, _)), _) =>
    Unmarshal(entity).to[String].map(response => {
      Right(response)
    })
  case (Failure(ex), _) =>
    Future(Left(Error(ex)))
}

For some reason not all request responses are being processed. Some results in error:

a.h.i.e.c.PoolGateway - [0 (WaitingForResponseEntitySubscription)] Response entity was not subscribed after 1 second. Make sure to read the response entity body or call `discardBytes()` on it.

How to subscribe to my response while maintaining the flow above?


回答1:


Although it's not the best solution, you can increase the response subscription timeout like this:

akka.http.host-connection-pool.response-entity-subscription-timeout = 10.seconds

Here is a more thorough discussion: https://github.com/akka/akka-http/issues/1836




回答2:


As suggested in docs, implementing entity handling the following way solves the issue:

          private val requestFlow: Flow[(HttpRequest, HelperClass), Either[Error, String], _] =
Http().cachedHostConnectionPoolHttps(BaseUrl).mapAsync(1) {
  case (Success(HttpResponse(_, _, entity, _)),    _) =>
      entity.dataBytes
        .runReduce(_ ++ _)
        .map(r => Right(r.toString))
  case (Failure(ex), _) =>
    Future(Left(Error(ex)))
}


来源:https://stackoverflow.com/questions/62053942/akka-http-error-response-entity-was-not-subscribed-after-1-second

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!