- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在使用响应式(Reactive)伪装客户端 (com.playtika.reactivefeign:feign-reactor-spring-cloud-starter:3.2.0)
断路器版本:org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j:2.1.0
和 spring boot 应用程序版本 org.springframework.boot' version '2.6.6
当我们从响应式(Reactive)伪装客户端收到错误(例如 404 错误)时
@ReactiveFeignClient(name = "someRestClient", url = "${react-gpi-service.url}",configuration = AuthConfigurationsomeRestClient.class, fallbackFactory = someRestClienttFallbackFactory.class)
@Profile("!test")
public interface someRestClient {
@PostMapping(value = "/v2/{entity}/any", produces = MediaType.ALL_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
Mono<String> any(@PathVariable(value = "entity")
它遍历错误解码器以检查是否应该重试
@Slf4j
@RequiredArgsConstructor
public class RetryableErrorDecoder implements ErrorDecoder {
private static ErrorDecoder defaultErrorDecoder = new Default();
private final String clientName;
public Exception decode(String methodKey, Response response) {
String body = "";
try {
body = IOUtils.toString(response.body().asInputStream(), StandardCharsets.UTF_8);
} catch (Exception e) {
log.error("failed to parse error response body", e);
}
log.error("In RetryableErrorDecoder, got an error from {}. status: {}, body: {}, reason: {}, request: {}",
clientName, response.status(), body, response.reason(), response.request());
if (response.status() == HttpStatusCodes.STATUS_CODE_SERVICE_UNAVAILABLE ||
response.status() == HttpStatusCodes.STATUS_CODE_BAD_GATEWAY) {
log.warn("Retry on error 503 or 502");
return createRetryableException(response, "Service Unavailable 503, 502");
} else {
Exception decode = defaultErrorDecoder.decode(methodKey, response);
if (decode instanceof FeignException &&
decode.getMessage().contains("authorizing")) {
log.warn("Retry on {}", decode.getMessage());
return createRetryableException(response, "Service authorizing problem");
}
return decode;
}
}
private Exception createRetryableException(Response response, String message) {
return new RetryableException(
response.status(),
message,
response.request().httpMethod(),
null,
null,
response.request());
}
}
之后进入 Circuit beaker 谓词
public class someFailurePredicate implements Predicate<Throwable> {
@Override
public boolean test(Throwable throwable) {
return throwable instanceof ThirdPartyException
|| throwable instanceof ReadTimeoutException
|| throwable instanceof OutOfRetriesException;
}
}
然后进入 fallBackFactory 机制,因为断路器需要 fallback 方法,所以断路器谓词再次被激活。
@Component
public class someRestClientFallbackFactory implements FallbackFactory<someRestClient> {
@Override
public someRestClient apply(Throwable throwable) {
return new someRestClientFallback(throwable);
}
}
public class someRestClientFallback implements someRestClient {
private final Throwable cause;
public someClientFallback(Throwable cause) {
this.cause = cause;
}
public Mono<String> performSearchRequest(String entity,
) {
return Mono.error(cause);
}
}
因为我们有 2 种错误处理机制,电路谓词调用两次并复制错误。
我尝试将重试机制(错误解码器)移至回退方法,但回退工厂方法接受可抛出的并且 reactiveFeignClientException 没有状态代码,因此很难确定我们是否应该进行重试。
如果我删除后备方法,我会收到此错误消息:
org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException: No fallback available.
我们需要添加它,但是我们有两个机制和一个重复的断路器谓词计数
最佳答案
Reactive Feign Client 默认启用自己的 CB,可以通过将 reactive.feign.circuit.breaker.enabled 设置为 false 来禁用它 - https://github.com/PlaytikaOSS/feign-reactive/blob/develop/feign-reactor-spring-configuration/README.md
关于spring-boot - 使用 reactiveFeignClient 和 CircuitBreaker 进行错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74852509/
我有一个带有 Jubilee 的 Spring Boot 2.6.0-M1 项目(但问题可以从 2.4 开始重现)。在我的项目中,我使用了 Actuator、Spring cloud Kubernet
我遇到了@CircuitBreaker 没有重试的问题。 我有一个服务类(例如 UserService 类和方法名称 getUser),此方法调用另一个 Spring bean(例如 AppClien
是否可以监控所有Circuit Breakers限制和大小? Fielddata Breaker可以通过节点使用它来监控: GET _nodes/stats/breaker,http 但是我们如何监控
我有一个 spring boot 应用程序,它迭代地调用 mockserver通过 hystrix 命令实例化,带有回退方法。 模拟服务器被配置为始终以状态代码 500 响应。当在没有 circuit
我们正在使用响应式(Reactive)伪装客户端 (com.playtika.reactivefeign:feign-reactor-spring-cloud-starter:3.2.0) 断路器版本
我尝试将重试策略与带有 Failsafe 的 CircuitBreaker 模式结合起来,但当尝试打开电路并中断时,我收到了 CircuitBreakerOpenException 异常。 https
CircuitBreaker CircuitBreaker主要分为以下几个模块:熔断器配置,熔断器注册,熔断事件消费者注册,熔断器状态机,熔断器状态及指标,熔断器事件,熔断器事件处理器,熔断器
我在 Gradle 中使用 Spring Boot 2.4。 这是我定义依赖项的方式: compile 'org.springframework.cloud:spring-cloud-starter-
我正在尝试为我的 Rest 客户创建一个综合弹性策略,为此我编写了以下内容: private static Policy circuitBreakerPolicy = Policy .Han
我正在尝试使用 Resilience4j 的 Spring Boot 注释。 当我使用注释时@CircuitBreaker(name = BACKEND,fallbackMethod = "fallb
尽管对于其他返回类型,Spring 重试回退机制似乎工作正常,但是当涉及到调用返回类型为 void 的 API 时。恢复方法根本没有被调用,我已经尝试了所有可能的方法参数类型并更改了后备方法的返回类型
Spring 的@Retryable 注释将重试三次(默认)并回退到@Recovery 方法。然而,@CircuitBreaker 将重试一次并在状态关闭时回退。 我想结合这两者:当断路器状态为关闭时
现在我在 hystrix 中使用 feign,结果发现,当 fallback 方法在 5 秒内调用 20 次时,Circuit 将变为 Open 状态。我怎样才能改变这个规则。例如,当fallback
我有一个通过 REST 调用依赖项的服务。服务和依赖是微服务架构的一部分,所以我想使用弹性模式。我的目标是: 有一个断路器来保护它挣扎时的依赖 限制调用可以运行的时间。该服务具有 SLA,并且必须在特
我正在使用 spring boot 1.3.1 和 spring cloudl Brixtom.M4,在使用 springboot 1.3.1 时我发现 Turbine-AMQP 项目不再可用,我们现
我是一名优秀的程序员,十分优秀!