我有两个Scala + Play Framework应用程序,它们与HTTP请求进行通信。
发行场景:
一个应用程序让我们说A正在从外部(例如Postman)获取请求,它所做的一切只是将请求重定向到应用程序B。控制器代码:
SecuredAction.async(parse.json[JsObject]) { implicit request =>
implicit val user: User = request.identity
withMetrics {
appBclient.doCalculations(request.body, <some query params>)
} toResult
}
对于那些想知道什么是Metrics的人来说:
protected def withMetrics(res: => Future[JsObject]): Future[JsObject] = {
val timer = txScoreTimer.start()
res.transform(
{ json => json ++ Json.obj("_api" -> Json.obj( "processingTimeSeconds" ->
timer.observe)) },
{ e: Throwable =>
val tookSeconds = timer.observe
e match {
case g: GeneralException => g.copy(processingTimeSeconds = Some(tookSeconds))
case _ => e
}
}
)
}
应用程序B计算的东西真的很长的时间,所以应用程序A得到超时异常后120秒:
java.util.concurrent.TimeoutException: Request timeout to host after 120000 ms
at play.shaded.ahc.org.asynchttpclient.netty.timeout.TimeoutTimerTask.expire(TimeoutTimerTask.java:43)
at play.shaded.ahc.org.asynchttpclient.netty.timeout.RequestTimeoutTimerTask.run(RequestTimeoutTimerTask.java:48)
at play.shaded.ahc.io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:663)
at play.shaded.ahc.io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:738)
at play.shaded.ahc.io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:466)
at java.lang.Thread.run(Thread.java:750)
之后,应用程序B在失败后一段时间再次收到这个确切的请求,但我可以看到,在我的代码中没有重试的逻辑。
所以我的问题是有什么可能导致这个问题,也许是一些应用程序或Play框架的env变量,我真的很困惑。
1条答案
按热度按时间lyfkaqu11#
对不起,我想发表评论,但我还没有StackOverflow的要点。
我不确定这是否适用,我肯定认为这是一个有点麻烦,但你有没有想过创建一个JobScheduler系统?对AppA的调用将向AppB添加注册新的异步函数作为具有挂起状态的新作业,并返回jobId。async函数将调用AppB,但也将响应关联到jobId,更新作业状态。然后使用jobId为AppA创建一个新的轮询端点。
只是一个想法。干杯