英文:
Spring Circuit Breaker - Resilience4j - how to configure?
问题
关于 Spring Cloud Circuit Breaker 与 Resilience4J(不是单独的 Resilience4J)我有一个简短的问题。
这两个项目都非常出色。然而,目前我们经常陷入回退状态。也就是说,当第三方服务实际上是正常的时候,我们最终还是会进入回退状态。
这可能是我的问题,因此,我想针对特定配置提问。
我想要对当前的配置做以下设定:
电路断路器(我将使用良好、糟糕以及一半良好/一半糟糕的状态)。
-
当状态良好时:在可配置的次数之后(比如说取 5 次),请求失败(第三方 API 出现问题)时,将其置为一半良好/一半糟糕的状态。
-
当状态为一半良好/一半糟糕时:一旦处于一半良好/糟糕的状态,并且超过一半(可配置)的请求成功了,将其恢复到良好状态。
-
当状态为一半良好/一半糟糕时:如果超过一半的请求仍然失败,将其置为糟糕状态。
-
当状态为糟糕时:经过两次连续的成功请求,将其恢复到一半良好一半糟糕的状态。
-
请求的超时时间应为 4 秒内应有响应。这是第三方提供给我们的 SLA。超过这个时间,可能有问题。
-
每次失败的请求,最多重试 3 次(可配置)。
请问如何在 Spring Webflux 中实现这些配置?
谢谢
英文:
I have a quick question regarding Spring Cloud Circuit Breaker with Resilience4J (not Resilience4J alone).
Both projects are pretty awesome. However, currently, we ended in the fallback too often. That means, when the 3rd party service is actually fine, we still end up going to the fallback.
This is probably my own issue, hence, I would like to ask a question for a particular configuration.
I would like to tell the current Configuration to do the following:
The circuit breaker. (I am going to use good, bad, and half good/half bad states.
-
When state is good: After a configurable number (let's take 5 for example) failed requests (something is wrong on the 3rd party API), put to half good/half bad.
-
When state is half good/half bad: Once in half good/bad, if more than half (configurable) of the requests are success, put if back to good state.
-
When state is half good/half bad: If more than half of the requests are still failing, put to bad state.
-
When state is bad: After two consecutive good requests, put it back to half good half bad.
-
For the time out, a request should answer within 4 seconds. It is the SLA the 3rd party gave us. Above that, probably something is wrong.
-
For each failed request, a retry of 3 (configurable) times.
May I ask how to achieve that please in Spring Webflux?
Thank you
答案1
得分: 2
这是不可能的:
> 当状态不好时:在两个连续的良好请求之后,将其恢复为一半良好一半不良。
当断路器处于打开状态时,不允许进行任何调用。
如果您使用resilience4j-spring-boot2
和resilience4j-reactor
,就可以轻松实现这一点。
publisher
.transform(TimeLimiterOperator.of(timeLimiter))
.transform(CircuitBreakerOperator.of(circuitBreaker))
.transform(RetryOperator.of(retry))
我们的Spring Boot启动器允许您在外部配置文件中配置TimeLimiter、CircuitBreaker和Retry。您甚至可以只在方法上使用注解。无需手动添加Reactor操作符。
@TimeLimiter(name = "id")
@CircuitBreaker(name = "id")
@Retry(name = "id")
public Flux<String> fluxSuccess() {
return Flux.just("Hello", "World");
}
而且我们的Spring Boot启动器会添加指标
详情请参阅:https://resilience4j.readme.io/docs/getting-started-3
英文:
This is not possible:
> When state is bad: After two consecutive good requests, put it back to half good half bad.
When the CircuitBreaker is open, it does not permit any calls.
You can achieve this easily if you use resilience4j-spring-boot2
and resilience4j-reactor
.
publisher
.transform(TimeLimiterOperator.of(timeLimiter))
.transform(CircuitBreakerOperator.of(circuitBreaker))
.transform(RetryOperator.of(retry))
Our Spring Boot starter allows you to configure TimeLimiter, CircuitBreaker and Retry in your external configuration file. You can even just use Annotations on your methods. No need to add the Reactor operators manually.
@TimeLimiter(name = "id")
@CircuitBreaker(name = "id")
@Retry(name = "id")
public Flux<String> fluxSuccess() {
return Flux.just("Hello", "World");
}
And our Spring Boot starter adds metrics
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论