@Test public void testRateLimiterRegistry() { io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties instanceProperties1 = new io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties(); instanceProperties1.setLimitForPeriod(2); instanceProperties1.setSubscribeForEvents(true); io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties instanceProperties2 = new io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties(); instanceProperties2.setLimitForPeriod(4); instanceProperties2.setSubscribeForEvents(true); RateLimiterConfigurationProperties rateLimiterConfigurationProperties = new RateLimiterConfigurationProperties(); rateLimiterConfigurationProperties.getInstances().put("backend1", instanceProperties1); rateLimiterConfigurationProperties.getInstances().put("backend2", instanceProperties2); rateLimiterConfigurationProperties.setRateLimiterAspectOrder(300); RateLimiterConfiguration rateLimiterConfiguration = new RateLimiterConfiguration(); DefaultEventConsumerRegistry<RateLimiterEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); RateLimiterRegistry rateLimiterRegistry = rateLimiterConfiguration .rateLimiterRegistry(rateLimiterConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRateLimiterCustomizerTest()); assertThat(rateLimiterConfigurationProperties.getRateLimiterAspectOrder()).isEqualTo(300); assertThat(rateLimiterRegistry.getAllRateLimiters().size()).isEqualTo(2); RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter("backend1"); assertThat(rateLimiter).isNotNull(); assertThat(rateLimiter.getRateLimiterConfig().getLimitForPeriod()).isEqualTo(2); RateLimiter rateLimiter2 = rateLimiterRegistry.rateLimiter("backend2"); assertThat(rateLimiter2).isNotNull(); assertThat(rateLimiter2.getRateLimiterConfig().getLimitForPeriod()).isEqualTo(4); assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(2); }
@Bean public RateLimiterRegistry rateLimiterRegistry( RateLimiterConfigurationProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer, @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer) { RateLimiterRegistry rateLimiterRegistry = createRateLimiterRegistry(rateLimiterProperties, rateLimiterRegistryEventConsumer, compositeRateLimiterCustomizer); registerEventConsumer(rateLimiterRegistry, rateLimiterEventsConsumerRegistry, rateLimiterProperties); rateLimiterProperties.getInstances().forEach( (name, properties) -> rateLimiterRegistry .rateLimiter(name, rateLimiterProperties .createRateLimiterConfig(properties, compositeRateLimiterCustomizer, name)) ); return rateLimiterRegistry; }
RateLimiterConfiguration { @Bean public RateLimiterRegistry rateLimiterRegistry( RateLimiterConfigurationProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer, @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer) { RateLimiterRegistry rateLimiterRegistry = createRateLimiterRegistry(rateLimiterProperties, rateLimiterRegistryEventConsumer, compositeRateLimiterCustomizer); registerEventConsumer(rateLimiterRegistry, rateLimiterEventsConsumerRegistry, rateLimiterProperties); rateLimiterProperties.getInstances().forEach( (name, properties) -> rateLimiterRegistry .rateLimiter(name, rateLimiterProperties .createRateLimiterConfig(properties, compositeRateLimiterCustomizer, name)) ); return rateLimiterRegistry; } }
RateLimiterConfiguration { @Bean public RateLimiterRegistry rateLimiterRegistry( RateLimiterConfigurationProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer, @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer) { RateLimiterRegistry rateLimiterRegistry = createRateLimiterRegistry(rateLimiterProperties, rateLimiterRegistryEventConsumer, compositeRateLimiterCustomizer); registerEventConsumer(rateLimiterRegistry, rateLimiterEventsConsumerRegistry, rateLimiterProperties); rateLimiterProperties.getInstances().forEach( (name, properties) -> rateLimiterRegistry .rateLimiter(name, rateLimiterProperties .createRateLimiterConfig(properties, compositeRateLimiterCustomizer, name)) ); return rateLimiterRegistry; }  }
RateLimiterConfiguration { @Bean public RateLimiterRegistry rateLimiterRegistry( RateLimiterConfigurationProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer, @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer) { RateLimiterRegistry rateLimiterRegistry = createRateLimiterRegistry(rateLimiterProperties, rateLimiterRegistryEventConsumer, compositeRateLimiterCustomizer); registerEventConsumer(rateLimiterRegistry, rateLimiterEventsConsumerRegistry, rateLimiterProperties); rateLimiterProperties.getInstances().forEach( (name, properties) -> rateLimiterRegistry .rateLimiter(name, rateLimiterProperties .createRateLimiterConfig(properties, compositeRateLimiterCustomizer, name)) ); return rateLimiterRegistry; }  @Bean @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer(
        @Nullable List<RateLimiterConfigCustomizer> configCustomizers); @Bean RateLimiterRegistry rateLimiterRegistry(
        RateLimiterConfigurationProperties rateLimiterProperties,
        EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry,
        RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer,
        @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer); @Bean @Primary RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer(
        Optional<List<RegistryEventConsumer<RateLimiter>>> optionalRegistryEventConsumers); @Bean @Conditional(value = {AspectJOnClasspathCondition.class}) RateLimiterAspect rateLimiterAspect(
        RateLimiterConfigurationProperties rateLimiterProperties,
        RateLimiterRegistry rateLimiterRegistry,
        @Autowired(required = false) List<RateLimiterAspectExt> rateLimiterAspectExtList,
        FallbackDecorators fallbackDecorators,
        SpelResolver spelResolver
    ); @Bean @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) RxJava2RateLimiterAspectExt rxJava2RateLimiterAspectExt(); @Bean @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) ReactorRateLimiterAspectExt reactorRateLimiterAspectExt(); @Bean EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry(); }
RateLimiterConfiguration { @Bean public RateLimiterRegistry rateLimiterRegistry( RateLimiterConfigurationProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer, @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer) { RateLimiterRegistry rateLimiterRegistry = createRateLimiterRegistry(rateLimiterProperties, rateLimiterRegistryEventConsumer, compositeRateLimiterCustomizer); registerEventConsumer(rateLimiterRegistry, rateLimiterEventsConsumerRegistry, rateLimiterProperties); rateLimiterProperties.getInstances().forEach( (name, properties) -> rateLimiterRegistry .rateLimiter(name, rateLimiterProperties .createRateLimiterConfig(properties, compositeRateLimiterCustomizer, name)) ); return rateLimiterRegistry; }  @Bean @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer(
        @Nullable List<RateLimiterConfigCustomizer> configCustomizers); @Bean RateLimiterRegistry rateLimiterRegistry(
        RateLimiterConfigurationProperties rateLimiterProperties,
        EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry,
        RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer,
        @Qualifier("compositeRateLimiterCustomizer") CompositeCustomizer<RateLimiterConfigCustomizer> compositeRateLimiterCustomizer); @Bean @Primary RegistryEventConsumer<RateLimiter> rateLimiterRegistryEventConsumer(
        Optional<List<RegistryEventConsumer<RateLimiter>>> optionalRegistryEventConsumers); @Bean @Conditional(value = {AspectJOnClasspathCondition.class}) RateLimiterAspect rateLimiterAspect(
        RateLimiterConfigurationProperties rateLimiterProperties,
        RateLimiterRegistry rateLimiterRegistry,
        @Autowired(required = false) List<RateLimiterAspectExt> rateLimiterAspectExtList,
        FallbackDecorators fallbackDecorators,
        SpelResolver spelResolver
    ); @Bean @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) RxJava2RateLimiterAspectExt rxJava2RateLimiterAspectExt(); @Bean @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) ReactorRateLimiterAspectExt reactorRateLimiterAspectExt(); @Bean EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry();  }