如何从application.properties创建断路器配置?

问题描述

我具有以下配置,可以在运行时创建断路器:


@Configuration
public class CircuitBreakerConfiguration
{

    public final static String DEFAULT_CIRCUIT_BREAKER_REGISTRY = "DEFAULT_CIRCUIT_BREAKER_REGISTRY";

    private CircuitBreakerConfig getCircuitBreakerConfig()
    {
        return CircuitBreakerConfig.custom()
                .failureRateThreshold(10)
                .waitDurationInopenState(Duration.ofMillis(30000))
                .permittednumberOfCallsInHalfOpenState(2)
                .slidingWindowType(CircuitBreakerConfig.SlidingWindowType.COUNT_BASED)
                .slidingWindowSize(5)
                .automaticTransitionFromOpenToHalfOpenEnabled(true)
                .recordExceptions(CheckAvailabilityException.class)
                .build();

    }

    @Bean
    @Qualifier(DEFAULT_CIRCUIT_BREAKER_REGISTRY)
    public CircuitBreakerRegistry getCircuitBreakerRegistry()
    {
        return CircuitBreakerRegistry.of(getCircuitBreakerConfig());
    }
}

我想将这些配置移到我的application.properties文件中。

我尝试了以下方法来覆盖认配置:

resilience4j.circuitbreaker.configs.default.sliding-window-size=10
resilience4j.circuitbreaker.configs.default.sliding-window-type=COUNT_BASED
resilience4j.circuitbreaker.configs.default.failure-rate-threshold=50
resilience4j.circuitbreaker.configs.default.wait-duration-in-open-state=30s
resilience4j.circuitbreaker.configs.default.permitted-number-of-calls-in-half-open-state=2
resilience4j.circuitbreaker.configs.default.automatic-transition-from-open-to-half-open-enabled=true
resilience4j.circuitbreaker.configs.default.record-exceptions=com.example.web.domain.checkavailability.exceptions.CheckAvailabilityException

但是,这似乎也不会覆盖认配置。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)