具有重试配置的 Resiliency4j 断路器不起作用
我在服务方法上同时使用 @CircuitBreaker
和 @Retry
注释。当我应用这两种配置时,重试配置不会生效。
下面是配置:
resilience4j:
circuitbreaker:
instances:
inventorymicroservice:
registerHealthIndicator: true
ringBufferSizeInClosedState: 5
ringBufferSizeInHalfOpenState: 3
waitDurationInOpenState: 30000
failureRateThreshold: 50
slowCallRateThreshold: 50
recordExceptions:
- java.io.IOException
- java.util.concurrent.TimeoutException
- java.net.ConnectException
- org.springframework.web.reactive.function.client.WebClientRequestException
retry:
instances:
retryConfig:
maxAttempts: 3
waitDuration: 10s
enableExponentialBackoff: true
exponentialBackoffMultiplier: 2
retryExceptions:
- org.springframework.web.client.HttpServerErrorException
- java.io.IOException
- java.io.IOException
- java.util.concurrent.TimeoutException
- java.net.ConnectException
- org.springframework.web.reactive.function.client.WebClientRequestException
服务方法:
@CircuitBreaker(name = "inventorymicroservice", fallbackMethod = "fallBack")
@Retry(name = "retryConfig", fallbackMethod = "fallBack")
public Order saveOrder(Order order){
Order savedOrder = this.orderRepository.save(order);
log.info("Calling the inventory service to update the quantity :: ");
//ResponseEntity<Integer> integerResponseEntity = this.restTemplate.postForEntity("http://localhost:9222/api/inventory", null, Integer.class);
Integer response = this.webClient
.post()
.uri("/api/inventory")
.retrieve()
.bodyToMono(Integer.class)
.block();
log.info("Response from the inventory microservice :: {}", response);
return savedOrder;
}
private Order fallBack(Throwable exception){
log.error("Exception while invoking the REST endpoint :: ", exception.getMessage());
return Order.builder().build();
}
我哪里出错了?另外,如何使用函数式编程将此配置转换为编程配置。
I am using both @CircuitBreaker
and @Retry
annotations on a service method. When I apply both the configurations, the retry configurations are not taking affect.
Below is the configuration:
resilience4j:
circuitbreaker:
instances:
inventorymicroservice:
registerHealthIndicator: true
ringBufferSizeInClosedState: 5
ringBufferSizeInHalfOpenState: 3
waitDurationInOpenState: 30000
failureRateThreshold: 50
slowCallRateThreshold: 50
recordExceptions:
- java.io.IOException
- java.util.concurrent.TimeoutException
- java.net.ConnectException
- org.springframework.web.reactive.function.client.WebClientRequestException
retry:
instances:
retryConfig:
maxAttempts: 3
waitDuration: 10s
enableExponentialBackoff: true
exponentialBackoffMultiplier: 2
retryExceptions:
- org.springframework.web.client.HttpServerErrorException
- java.io.IOException
- java.io.IOException
- java.util.concurrent.TimeoutException
- java.net.ConnectException
- org.springframework.web.reactive.function.client.WebClientRequestException
Service method:
@CircuitBreaker(name = "inventorymicroservice", fallbackMethod = "fallBack")
@Retry(name = "retryConfig", fallbackMethod = "fallBack")
public Order saveOrder(Order order){
Order savedOrder = this.orderRepository.save(order);
log.info("Calling the inventory service to update the quantity :: ");
//ResponseEntity<Integer> integerResponseEntity = this.restTemplate.postForEntity("http://localhost:9222/api/inventory", null, Integer.class);
Integer response = this.webClient
.post()
.uri("/api/inventory")
.retrieve()
.bodyToMono(Integer.class)
.block();
log.info("Response from the inventory microservice :: {}", response);
return savedOrder;
}
private Order fallBack(Throwable exception){
log.error("Exception while invoking the REST endpoint :: ", exception.getMessage());
return Order.builder().build();
}
Where am I going wrong? Also, how to convert this configuration to programmatic configuration using functional programming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认的Resilience4j方面顺序是
你的CircuitBreaker有一个后备,所以它永远不会抛出异常,因此 Retry 永远不会看到失败的重试调用。
删除重试后备,并更改方面顺序,以便 CircuitBreaker 在重试后继续工作。
The default Resilience4j aspect order is
Your CircuitBreaker has a fallback, so it never throws an exception, so Retry never sees a failed invocation to retry.
Remove the Retry fallback, and change the aspect order so CircuitBreaker does its work after Retry.