Scala RestartSource.withBackoff永不结束
我正在尝试使用Akka创建Http客户端,并使用重试策略,在该策略中我希望最大重试次数,然后返回错误。有这个代码吗Scala RestartSource.withBackoff永不结束,scala,akka,akka-stream,akka-http,Scala,Akka,Akka Stream,Akka Http,我正在尝试使用Akka创建Http客户端,并使用重试策略,在该策略中我希望最大重试次数,然后返回错误。有这个代码吗 private def makeRequest[T](system: ActorSystem, host: String, unmarshallFunc: ResponseEntity => Future[Either[ServiceNowAccessExcep
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
启动后强制执行错误,并且它一直试图连接
知道我的代码有什么问题吗
问候。它经常重启吗?时间在这里很重要。从:<代码> Max RealEnter,重新启动的数量在分钟备份的时间范围内被覆盖到这个数量。< /代码>它也被弃用,您是否考虑用接受重新启动设置的版本替换它?