我有一个Spring Boot应用程序,它使用基于AOP的resilience4j @CircuitBreaker
。
现在,我想使断路器的信息在@CircuitBreaker
端点中可用,但在JSON输出中看不到/actuator/health
对象details.circuitBtreakers
。
通过比较,要使动态缓存信息出现在described in the docs端点中,需要进行少量的自定义接线,但这是/actuator/metrics
。我想知道是否有类似的技巧可以申请动态定义的well documented来向@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
动态地为HealthIndicator端点注册CircuitBreakers目前不起作用。不幸的是,您必须配置它们:
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
您可以说这是一个错误。
resilience4j.circuitbreaker:
configs:
default:
registerHealthIndicator: true
instances:
myCB:
baseConfig: default