resilience4j版本:1.6.1
我们有一个restapi,可以进行一些后端调用。我们有一个使用时间限制器和带回退的断路器的用例
下面的代码是bean的init()方法(spring)的一部分:
scheduler = Executors.newScheduledThreadPool(100);
cmplStage = new DecorateCompletionStage<AccountinformationRequest>(
() -> CompletableFuture.supplyAsync{
() -> updatePPA(this.ResilienceRequest)));
Function<Throwable,AccountInformationRequest> backupCall =
(Throwable) -> FallBackupdatePPA(Throwable, this.ResilienceRequest);
List<Class<? extends Throwable>> exList = new ArrayList<Class<? extends Throwable>>();
exList.add(CallNotPermittedException.class);
//With TimeLimiter & CircuitBreaker
decorator = cmplStage
.withTimeLimiter(timeLimiterBean.timeLimiterUpdatePPA,scheduler)
.withCircuitBreaker(CbObject.circuitBreakerUpdatePPA)
.withFallback(exList, backupCall)
.decorate();
当restapi被触发时,我们调用这个decorator。
{
//Body
...
..
CompletableFuture<AccountInformationRequest> wrappedBackendCall = decorator.get().tocompletableFuture();
return wrappedBackendCall.join();
}
配置:
TimeLimiterConfig config = TimeLimiterConfig.custom()
.cancelRunningFuture(false)
.timeoutDuration(Duration.ofMillis(5000)).build();
CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
.minimumNumberOfCalls(1)
.failureRateThreshold(50)
.waitDurationInOpenState(Duration.ofMillis(2500))
.permittedNumberOfCallsInHalfOpenState(2)
.slidingWindowSize(4)
.ignoreExceptions(NullPointerException.class)
.build();
当多个客户机同时访问这个restapi时,在使用timitlimer和cirucitbreaker装饰器之后,响应时间非常长。
你能帮我纠正我的方法或配置吗?
暂无答案!
目前还没有任何答案,快来回答吧!