英文:
How to configure to events in Resilience4j Spring starter
问题
@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());
}
英文:
I have configured by resilience4j circuitbreaker factory bean like below.But i couldnot get a function to ovveride event listeners example to open , close etc .Please help
@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());
}
答案1
得分: 3
我推荐使用 resilience4j-spring-boot2
。它提供了许多功能,如注解支持、外部配置、指标等等 -> https://resilience4j.readme.io/docs/getting-started-3
我们的起始包支持以下内容:
您可以添加一个 RegistryEventConsumer
bean,以便向新创建的实例添加事件消费者。
例如,您可以向 CircuitBreakerRegistry 添加一个 RegistryEventConsumer,以便将日志事件消费者注册到每个新创建的 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) {
}
};
}
英文:
I recommend to use resilience4j-spring-boot2
. It provides a lot features like annotation support, external configuration, metrics, and many more -> https://resilience4j.readme.io/docs/getting-started-3
Our starter supports the following:
You can add a RegistryEventConsumer
bean in order to add event consumers to newly created instances.
For example, you can add an RegistryEventConsumer to the CircuitBreakerRegistry in order to register a logging event consumer to every newly created CircuitBreaker instance.
@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) {
}
};
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论