【发布时间】:2020-10-29 22:27:02
【问题描述】:
我正在学习 Akka 库,我已经使用 Play 框架在我的系统中设置了一个本地服务器,我正在 使用 Akka 库编写客户端应用程序。
implicit val system = ActorSystem("testing")
implicit val materializer = ActorMaterializer()
import system.dispatcher
val serverHttpRequests = files.map { file =>
(
HttpRequest (
HttpMethods.POST,
uri = Uri(Url),
entity = HttpEntity(
ContentTypes.`text/plain(UTF-8)`,
getChartData(file) // reading file from local file system
)
), file.getName
)
}
val res = Source(serverHttpRequests)
.via(Http().cachedHostConnectionPool[String]("localhost", 9001))
.runForeach {
case (Success(response), fileName) => logger.info(s"$fileName, $response")
response.discardEntityBytes()
case (Failure(ex), fileName) => logger.info(s"$fileName failed with $ex")
}
文件很少,需要1分钟以上才能得到本地服务器的响应,
对于这些文件,我收到以下异常fileName failed with akka.stream.StreamTcpException: The connection closed with error: An existing connection was forcibly closed by the remote host
我尝试将客户端和服务器的超时时间增加到 300 秒。
客户application.conf
akka.http.client.idle-timeout = 300s
akka.http.client.connecting-timeout = 300s
服务器application.conf
akka.http.host-connection-pool.idle-timeout = 300s
akka.http.host-connection-pool.client.idle-timeout = 300s
play.server.akka.https.idleTimeout = 300s
play.server.akka.requestTimeout = 300s
play.server.akka.terminationTimeout = 300s
akka.http.server.bind-timeout = 300s
对于上面的代码,我正在尝试处理 10 个文件,每个文件的大小都小于20 KB,并且响应
从服务器,平均每个文件将小于120 KB。
我还读到 Akka IO.selectors 将通过发送心跳来保持连接,
我正在尝试了解此异常的确切原因并进行处理。
【问题讨论】:
标签: scala playframework akka akka-http connection-timeout