4

我有一个 Spring Boot 应用程序,它使用基于Resilience4j AOP 的@CircuitBreakers。

现在我想在/actuator/health端点中提供断路器的信息,但我没有在 JSON 输出中看到文档中描述details.circuitBtreakers的对象。

我究竟做错了什么?


相比之下,让动态缓存信息出现在/actuator/metrics端点中需要少量的自定义连接,但这是有据可查的。我想知道是否有类似的技巧可以申请动态定义@CircuitBreaker的 s 向/actuator/health端点注册。

MyService.java

@Service
public class MyService {
    @Autowired
    private CacheManager cacheManager;
    @Autowired
    private CacheMetricsRegistrar cacheMetricsRegistrar;

    @PostConstruct
    public void postConstruct() {
        // On-the-fly defined (annotation-based) caches are not auto-registered with micrometer metrics.
        final Cache cache = cacheManager.getCache("myCache");
        cacheMetricsRegistrar.bindCacheToRegistry(cache);
    }

    @CircuitBreaker(name = "myCB", fallbackMethod = "fallbackCallAnApi")
    public String callAnApi() throws RestClientException {
        // ...
    }

    @Cacheable("myCache")
    public String getSomethingCacheable() {
        // ...
    }
}

application.properties

resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true
management.endpoints.web.expose=health,metrics
management.endpoints.web.exposure.include=health,metrics
management.endpoint.health.enabled=true
management.endpoint.metrics.enabled=true
management.metrics.enable.resilience4j.circuitbreaker.calls=true
management.health.circuitbreakers.enabled=true
4

1 回答 1

3

为 HealthIndicator 端点动态注册断路器目前不起作用。不幸的是,您必须配置它们:

resilience4j.circuitbreaker:
    configs:
        default:
            registerHealthIndicator: true
    instances:
        myCB:
            baseConfig: default

你可以说这是一个错误。

https://github.com/resilience4j/resilience4j/blob/master/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/monitoring/health/CircuitBreakersHealthIndicator.java#L99-L102

于 2020-03-05T06:33:43.613 回答