问题
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