如何解决RestartSource.withBackoff永远不会结束
我正在尝试使用Akka创建具有重试策略的Http客户端,在该策略中,我希望最大重试次数,然后返回错误。有此代码
private def makeRequest[T](system: ActorSystem,host: String,unmarshallFunc: ResponseEntity => Future[Either[ServiceNowAccessException,T]]): Future[Either[ServiceNowAccessException,T]] = {
implicit val mat: Materializer = Materializer(system)
RestartSource.withBackoff(
minBackoff = 10 seconds,maxBackoff = 10 seconds,randomFactor = 0.2,maxRestarts = 2
) { () =>
Source.future(Http()(system).singleRequest(HttpRequest(uri = host)))
.mapAsync(parallelism = 1) {
case HttpResponse(OK,_,entity,_) => unmarshallFunc(entity)
case HttpResponse(InternalServerError,_) =>
Future(Left(ServiceNowAccessException(InternalServerError.intValue)))
case HttpResponse(statusCode,_) =>
Future(Left(ServiceNowAccessException(statusCode.intValue())))
}
}.runWith(Sink.head)
}
maxRestarts
之后,我无法强制执行该错误,并且它一直试图永久连接。
任何想法我的代码有什么问题
致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。