![](/img/trans.png)
[英]@Recover (fallback method) is not getting invoked when used with @CircuitBreaker, once all the retry gets exhaused
[英]CircuitBreaker Fallback method not working
我在計費服務微服務中有以下代碼:
@RestController
@RequestMapping("/billing")
public class WebController {
@Autowired
private BillingService service;
@GetMapping("/hi")
@CircuitBreaker(name="BillingServiceCapture", fallbackMethod = "hiFallback")
public String hi() {
return "Hello Khushboo!";
}
public String hiFallback() {
return "Hello Khushboo FallBack!";
}
應用程序.屬性文件:
server.port=9191
spring.h2.console.enable=true
spring.application.name=billing-service
eureka.client.serviceurl.defaultzone=http://localhost:8761/eureka
eureka.instance.hostname=localhost
management.health.circuitbreakers.enabled=true
#actuator settings
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
resilience4j.circuitbreaker.instances.BillingServiceCapture.registerHealthIndicator=true
resilience4j.circuitbreaker.instances.BillingServiceCapture.eventConsumerBufferSize=10
resilience4j.circuitbreaker.instances.BillingServiceCapture.failureRateThreshold=20
resilience4j.circuitbreaker.instances.BillingServiceCapture.minimumNumberOfCalls=5
resilience4j.circuitbreaker.instances.BillingServiceCapture.automaticTransitionFromOpenToHalfOpenEnabled=true
resilience4j.circuitbreaker.instances.BillingServiceCapture.waitDurationInOpenState=5s
resilience4j.circuitbreaker.instances.BillingServiceCapture.permittedNumberOfCallsInHalfOpenState=3
resilience4j.circuitbreaker.instances.BillingServiceCapture.slidingWindowSize=10
resilience4j.circuitbreaker.instances.BillingServiceCapture.slidingWindowType=COUNT_BASED
但是,如果我發送 Get Request: localhost:8765/billing/hi 我會收到 Hello Khushboo 消息。
但是當我停止 BillingService 微服務並再次發送相同的請求時,不會調用斷路器方法。
此外,在訪問 Actuator Health 狀態時,我沒有在我應該看到的狀態日志中看到斷路器信息。
任何見解將不勝感激。
謝謝。
回退方法應傳遞 Exception 參數:
public String hiFallback(Exception e) {
return "Hello Khushboo FallBack!";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.