gpt4 book ai didi

java - 如何在 Resilience4j Spring starter 中配置事件

转载 作者:行者123 更新时间:2023-12-04 15:19:23 25 4
gpt4 key购买 nike

我已经通过 resilience4j circuitbreaker factory bean 进行了配置,如下所示。但是我无法获得 ovveride 事件监听器示例的功能以打开、关闭等。请帮忙

@Bean
public Customizer<Resilience4JCircuitBreakerFactory> globalCustomConfiguration() {
CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
.failureRateThreshold(Float.parseFloat(failureRateThreshold))
.waitDurationInOpenState(Duration.ofMillis(Long.parseLong(waitDurationInOpenState)))
.slidingWindowSize(Integer.parseInt(slidingWindowSize)).build();
TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
.timeoutDuration(Duration.ofSeconds(Long.parseLong(timelimiterDuration))).build();

// the circuitBreakerConfig and timeLimiterConfig objects
return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
.timeLimiterConfig(timeLimiterConfig).circuitBreakerConfig(circuitBreakerConfig).build());
}

最佳答案

我推荐使用resilience4j-spring-boot2。它提供了许多功能,如注释支持、外部配置、指标等等 -> https://resilience4j.readme.io/docs/getting-started-3

我们的 starter 支持以下内容:

您可以添加一个 RegistryEventConsumer bean,以便将事件消费者添加到新创建的实例中。例如,您可以将 RegistryEventConsumer 添加到 CircuitBreakerRegistry,以便将日志记录事件使用者注册到每个新创建的 CircuitBreaker 实例。

@Bean
public RegistryEventConsumer<CircuitBreaker> myRegistryEventConsumer() {

return new RegistryEventConsumer<CircuitBreaker>() {
@Override
public void onEntryAddedEvent(EntryAddedEvent<CircuitBreaker> entryAddedEvent) {
entryAddedEvent.getAddedEntry().getEventPublisher().onEvent(event -> LOG.info(event.toString()));
}

@Override
public void onEntryRemovedEvent(EntryRemovedEvent<CircuitBreaker> entryRemoveEvent) {

}

@Override
public void onEntryReplacedEvent(EntryReplacedEvent<CircuitBreaker> entryReplacedEvent) {

}
};
}

关于java - 如何在 Resilience4j Spring starter 中配置事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63681211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com