Search in sources :

Example 1 with InMemoryRateLimiterRegistry

use of io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry in project resilience4j by resilience4j.

the class RateLimiterExportsTest method testConstructors.

@Test
public void testConstructors() {
    final RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(RateLimiterConfig.ofDefaults());
    RateLimiterExports.ofIterable("boo_limiters", singleton(RateLimiter.ofDefaults("foo")));
    RateLimiterExports.ofRateLimiterRegistry("boo_limiters", registry);
    RateLimiterExports.ofSupplier("boo_limiters", () -> singleton(RateLimiter.ofDefaults("foo")));
    RateLimiterExports.ofIterable(singleton(RateLimiter.ofDefaults("foo")));
    RateLimiterExports.ofRateLimiterRegistry(registry);
    RateLimiterExports.ofSupplier(() -> singleton(RateLimiter.ofDefaults("foo")));
}
Also used : InMemoryRateLimiterRegistry(io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry) InMemoryRateLimiterRegistry(io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) Test(org.junit.Test)

Example 2 with InMemoryRateLimiterRegistry

use of io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry in project resilience4j by resilience4j.

the class RateLimiterAutoConfiguration method rateLimiterRegistry.

@Bean
public RateLimiterRegistry rateLimiterRegistry(RateLimiterProperties rateLimiterProperties, EventConsumerRegistry<RateLimiterEvent> rateLimiterEventsConsumerRegistry, ConfigurableBeanFactory beanFactory) {
    RateLimiterRegistry rateLimiterRegistry = new InMemoryRateLimiterRegistry(RateLimiterConfig.ofDefaults());
    rateLimiterProperties.getLimiters().forEach((name, properties) -> {
        RateLimiter rateLimiter = createRateLimiter(rateLimiterRegistry, name, properties);
        if (properties.getSubscribeForEvents()) {
            subscribeToLimiterEvents(rateLimiterEventsConsumerRegistry, name, properties, rateLimiter);
        }
        if (properties.getRegisterHealthIndicator()) {
            createHealthIndicatorForLimiter(beanFactory, name, rateLimiter);
        }
    });
    return rateLimiterRegistry;
}
Also used : InMemoryRateLimiterRegistry(io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry) InMemoryRateLimiterRegistry(io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) RateLimiter(io.github.resilience4j.ratelimiter.RateLimiter) Bean(org.springframework.context.annotation.Bean)

Aggregations

RateLimiterRegistry (io.github.resilience4j.ratelimiter.RateLimiterRegistry)2 InMemoryRateLimiterRegistry (io.github.resilience4j.ratelimiter.internal.InMemoryRateLimiterRegistry)2 RateLimiter (io.github.resilience4j.ratelimiter.RateLimiter)1 Test (org.junit.Test)1 Bean (org.springframework.context.annotation.Bean)1