喷射到 Akka HTTP 迁移:spray.can.client.request-timeout
Spray to Akka HTTP migration: spray.can.client.request-timeout
我正在将一个应用程序从 Spray 迁移到 Akka HTTP。在配置中,我有:
spray {
can {
client.request-timeout = infinite
}
}
Akka HTTP 的等效配置是什么?看来 request-timeout
现在只能在 server
上使用,而不是 client
。
见https://github.com/akka/akka-http/blob/master/akka-http-core/src/main/resources/reference.conf
来自 Akka-HTTP 文档 (http://doc.akka.io/docs/akka-http/current/scala/http/client-side/connection-level.html#timeouts)
Currently Akka HTTP doesn’t implement client-side request timeout
checking itself as this functionality can be regarded as a more
general purpose streaming infrastructure feature.
It should be noted that Akka Streams provide various timeout
functionality so any API that uses streams can benefit from the stream
stages such as idleTimeout, backpressureTimeout, completionTimeout,
initialTimeout and throttle. To learn more about these refer to their
documentation in Akka Streams (and Scala Doc).
基本上,选择权留给了用户,以将超时控制添加到他们的客户端流。例如,在 the docs 中显示的示例中,您可以添加一个 completionTimeout
阶段来实现此
val responseFuture: Future[HttpResponse] =
Source.single(HttpRequest(uri = "/"))
.via(connectionFlow)
.completionTimeout(5.seconds)
.runWith(Sink.head)
请注意,如果您在 infinite
超时后(根据您的 Spray 配置),将通过不添加任何超时阶段免费提供。
akka.http {
server {
idle-timeout = infinite
}
client {
idle-timeout = infinite
}
host-connection-pool {
idle-timeout = infinite
}
}
您可以选择客户部分。
我正在将一个应用程序从 Spray 迁移到 Akka HTTP。在配置中,我有:
spray {
can {
client.request-timeout = infinite
}
}
Akka HTTP 的等效配置是什么?看来 request-timeout
现在只能在 server
上使用,而不是 client
。
见https://github.com/akka/akka-http/blob/master/akka-http-core/src/main/resources/reference.conf
来自 Akka-HTTP 文档 (http://doc.akka.io/docs/akka-http/current/scala/http/client-side/connection-level.html#timeouts)
Currently Akka HTTP doesn’t implement client-side request timeout checking itself as this functionality can be regarded as a more general purpose streaming infrastructure feature.
It should be noted that Akka Streams provide various timeout functionality so any API that uses streams can benefit from the stream stages such as idleTimeout, backpressureTimeout, completionTimeout, initialTimeout and throttle. To learn more about these refer to their documentation in Akka Streams (and Scala Doc).
基本上,选择权留给了用户,以将超时控制添加到他们的客户端流。例如,在 the docs 中显示的示例中,您可以添加一个 completionTimeout
阶段来实现此
val responseFuture: Future[HttpResponse] =
Source.single(HttpRequest(uri = "/"))
.via(connectionFlow)
.completionTimeout(5.seconds)
.runWith(Sink.head)
请注意,如果您在 infinite
超时后(根据您的 Spray 配置),将通过不添加任何超时阶段免费提供。
akka.http {
server {
idle-timeout = infinite
}
client {
idle-timeout = infinite
}
host-connection-pool {
idle-timeout = infinite
}
}
您可以选择客户部分。