具有重试配置的 Resiliency4j 断路器不起作用
Resiliency4j circuit breaker with retry configuration not working
我在服务方法上同时使用了 @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();
}
我哪里错了?另外,如何使用函数式编程将此配置转换为程序化配置。
Retry( CircuitBreaker( RateLimiter( TimeLimiter( Bulkhead( function)))))
你的 CircuitBreaker 有回退,所以它永远不会抛出异常,所以 Retry 永远不会看到失败的调用来重试。
移除 Retry 回退,并更改方面顺序,以便 CircuitBreaker 在 Retry 之后继续工作。
resilience4j:
circuitbreaker:
circuitBreakerAspectOrder: 1
retry:
retryAspectOrder: 2
我在服务方法上同时使用了 @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();
}
我哪里错了?另外,如何使用函数式编程将此配置转换为程序化配置。
Retry( CircuitBreaker( RateLimiter( TimeLimiter( Bulkhead( function)))))
你的 CircuitBreaker 有回退,所以它永远不会抛出异常,所以 Retry 永远不会看到失败的调用来重试。
移除 Retry 回退,并更改方面顺序,以便 CircuitBreaker 在 Retry 之后继续工作。
resilience4j:
circuitbreaker:
circuitBreakerAspectOrder: 1
retry:
retryAspectOrder: 2