@Test @SuppressWarnings("deprecation") public void testCreateCircuitBreakerRegistryWithSharedConfigsUsingDeprecatedOptions() { InstanceProperties defaultProperties = new InstanceProperties(); defaultProperties.setRingBufferSizeInClosedState(1000); defaultProperties.setRingBufferSizeInHalfOpenState(100); InstanceProperties sharedProperties = new InstanceProperties(); sharedProperties.setRingBufferSizeInClosedState(1337); sharedProperties.setRingBufferSizeInHalfOpenState(1000); InstanceProperties backendWithDefaultConfig = new InstanceProperties(); backendWithDefaultConfig.setBaseConfig("default"); backendWithDefaultConfig.setRingBufferSizeInHalfOpenState(99); InstanceProperties backendWithSharedConfig = new InstanceProperties(); backendWithSharedConfig.setBaseConfig("sharedConfig"); backendWithSharedConfig.setRingBufferSizeInHalfOpenState(999); CircuitBreakerConfigurationProperties circuitBreakerConfigurationProperties = new CircuitBreakerConfigurationProperties(); circuitBreakerConfigurationProperties.getConfigs().put("default", defaultProperties); circuitBreakerConfigurationProperties.getConfigs().put("sharedConfig", sharedProperties); circuitBreakerConfigurationProperties.getInstances() .put("backendWithDefaultConfig", backendWithDefaultConfig); circuitBreakerConfigurationProperties.getInstances() .put("backendWithSharedConfig", backendWithSharedConfig); CircuitBreakerConfiguration circuitBreakerConfiguration = new CircuitBreakerConfiguration( circuitBreakerConfigurationProperties); DefaultEventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); CircuitBreakerRegistry circuitBreakerRegistry = circuitBreakerConfiguration .circuitBreakerRegistry(eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeCircuitBreakerCustomizerTestInstance()); assertThat(circuitBreakerRegistry.getAllCircuitBreakers().size()).isEqualTo(2); CircuitBreaker circuitBreaker1 = circuitBreakerRegistry .circuitBreaker("backendWithDefaultConfig"); assertThat(circuitBreaker1).isNotNull(); assertThat(circuitBreaker1.getCircuitBreakerConfig().getSlidingWindowSize()) .isEqualTo(1000); assertThat( circuitBreaker1.getCircuitBreakerConfig().getPermittedNumberOfCallsInHalfOpenState()) .isEqualTo(99); CircuitBreaker circuitBreaker2 = circuitBreakerRegistry .circuitBreaker("backendWithSharedConfig"); assertThat(circuitBreaker2).isNotNull(); assertThat(circuitBreaker2.getCircuitBreakerConfig().getSlidingWindowSize()) .isEqualTo(1337); assertThat( circuitBreaker2.getCircuitBreakerConfig().getPermittedNumberOfCallsInHalfOpenState()) .isEqualTo(999); CircuitBreaker circuitBreaker3 = circuitBreakerRegistry.circuitBreaker("unknownBackend"); assertThat(circuitBreaker3).isNotNull(); assertThat(circuitBreaker3.getCircuitBreakerConfig().getSlidingWindowSize()) .isEqualTo(1000); assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(3); }
@Bean public CircuitBreakerRegistry circuitBreakerRegistry( EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry, RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer, @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer) { CircuitBreakerRegistry circuitBreakerRegistry = createCircuitBreakerRegistry( circuitBreakerProperties, circuitBreakerRegistryEventConsumer, compositeCircuitBreakerCustomizer); registerEventConsumer(circuitBreakerRegistry, eventConsumerRegistry); initCircuitBreakerRegistry(circuitBreakerRegistry, compositeCircuitBreakerCustomizer); return circuitBreakerRegistry; }
CircuitBreakerConfiguration { @Bean public CircuitBreakerRegistry circuitBreakerRegistry( EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry, RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer, @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer) { CircuitBreakerRegistry circuitBreakerRegistry = createCircuitBreakerRegistry( circuitBreakerProperties, circuitBreakerRegistryEventConsumer, compositeCircuitBreakerCustomizer); registerEventConsumer(circuitBreakerRegistry, eventConsumerRegistry); initCircuitBreakerRegistry(circuitBreakerRegistry, compositeCircuitBreakerCustomizer); return circuitBreakerRegistry; } }
CircuitBreakerConfiguration { @Bean public CircuitBreakerRegistry circuitBreakerRegistry( EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry, RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer, @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer) { CircuitBreakerRegistry circuitBreakerRegistry = createCircuitBreakerRegistry( circuitBreakerProperties, circuitBreakerRegistryEventConsumer, compositeCircuitBreakerCustomizer); registerEventConsumer(circuitBreakerRegistry, eventConsumerRegistry); initCircuitBreakerRegistry(circuitBreakerRegistry, compositeCircuitBreakerCustomizer); return circuitBreakerRegistry; } CircuitBreakerConfiguration(
        CircuitBreakerConfigurationProperties circuitBreakerProperties); }
CircuitBreakerConfiguration { @Bean public CircuitBreakerRegistry circuitBreakerRegistry( EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry, RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer, @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer) { CircuitBreakerRegistry circuitBreakerRegistry = createCircuitBreakerRegistry( circuitBreakerProperties, circuitBreakerRegistryEventConsumer, compositeCircuitBreakerCustomizer); registerEventConsumer(circuitBreakerRegistry, eventConsumerRegistry); initCircuitBreakerRegistry(circuitBreakerRegistry, compositeCircuitBreakerCustomizer); return circuitBreakerRegistry; } CircuitBreakerConfiguration(
        CircuitBreakerConfigurationProperties circuitBreakerProperties); @Bean @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer(
        @Autowired(required = false) List<CircuitBreakerConfigCustomizer> customizers); @Bean CircuitBreakerRegistry circuitBreakerRegistry(
        EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry,
        RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer,
        @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer); @Bean @Primary RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer(
        Optional<List<RegistryEventConsumer<CircuitBreaker>>> optionalRegistryEventConsumers); @Bean @Conditional(value = {AspectJOnClasspathCondition.class}) CircuitBreakerAspect circuitBreakerAspect(
        CircuitBreakerRegistry circuitBreakerRegistry,
        @Autowired(required = false) List<CircuitBreakerAspectExt> circuitBreakerAspectExtList,
        FallbackDecorators fallbackDecorators,
        SpelResolver spelResolver
    ); @Bean @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) RxJava2CircuitBreakerAspectExt rxJava2CircuitBreakerAspect(); @Bean @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) ReactorCircuitBreakerAspectExt reactorCircuitBreakerAspect(); @Bean EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry(); void registerEventConsumer(CircuitBreakerRegistry circuitBreakerRegistry,
        EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry); }
CircuitBreakerConfiguration { @Bean public CircuitBreakerRegistry circuitBreakerRegistry( EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry, RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer, @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer) { CircuitBreakerRegistry circuitBreakerRegistry = createCircuitBreakerRegistry( circuitBreakerProperties, circuitBreakerRegistryEventConsumer, compositeCircuitBreakerCustomizer); registerEventConsumer(circuitBreakerRegistry, eventConsumerRegistry); initCircuitBreakerRegistry(circuitBreakerRegistry, compositeCircuitBreakerCustomizer); return circuitBreakerRegistry; } CircuitBreakerConfiguration(
        CircuitBreakerConfigurationProperties circuitBreakerProperties); @Bean @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer(
        @Autowired(required = false) List<CircuitBreakerConfigCustomizer> customizers); @Bean CircuitBreakerRegistry circuitBreakerRegistry(
        EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry,
        RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer,
        @Qualifier("compositeCircuitBreakerCustomizer") CompositeCustomizer<CircuitBreakerConfigCustomizer> compositeCircuitBreakerCustomizer); @Bean @Primary RegistryEventConsumer<CircuitBreaker> circuitBreakerRegistryEventConsumer(
        Optional<List<RegistryEventConsumer<CircuitBreaker>>> optionalRegistryEventConsumers); @Bean @Conditional(value = {AspectJOnClasspathCondition.class}) CircuitBreakerAspect circuitBreakerAspect(
        CircuitBreakerRegistry circuitBreakerRegistry,
        @Autowired(required = false) List<CircuitBreakerAspectExt> circuitBreakerAspectExtList,
        FallbackDecorators fallbackDecorators,
        SpelResolver spelResolver
    ); @Bean @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) RxJava2CircuitBreakerAspectExt rxJava2CircuitBreakerAspect(); @Bean @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) ReactorCircuitBreakerAspectExt reactorCircuitBreakerAspect(); @Bean EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry(); void registerEventConsumer(CircuitBreakerRegistry circuitBreakerRegistry,
        EventConsumerRegistry<CircuitBreakerEvent> eventConsumerRegistry);  }