Spring Boot Actuator 健康端点 + 动态 Resilience4j 断路器

6
我有一个使用resilience4j基于AOP的@CircuitBreaker的Spring Boot应用程序。
现在,我想在/actuator/health端点中提供断路器信息,但在JSON输出中没有看到文档中描述的details.circuitBtreakers对象
我做错了什么?
相比之下,让动态缓存信息在/actuator/metrics端点中显示需要一些自定义连接,但这有很好的文档记录。我想知道是否有类似的技巧可以应用于动态定义的@CircuitBreaker以在/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
2个回答

5

文档(以及您在此处的答案)显示如何配置它们,但端点是什么?https://<host>/actuator/health/circuitbreaker(s)无法工作。我已经猜测了一些其他排列组合,但到目前为止还没有成功。 - Geyser14
尽管我已经配置了management.health.circuitbreakers.enabled=true和resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true,但../actuator/health仅显示status=OK。 - Geyser14

1
晚了但肯定没错。 使用HTTP需要额外的配置。
management:
  security:
    enabled:false
  health:
    circuitbreakers:
      enabled: true
  endpoint:
    health:
      show-details: "ALWAYS"
  endpoints:
    web:
      exposure:
        include: "*"

resilience4j.circuitbreaker:
    configs:
        default:
           registerHealthIndicator: true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接