HomeGuidesChangelog
GuidesGitHubLog In
Guides

Examples

Examples of resilience4j-ratelimiter

Create a RateLimiterRegistry

Create a RateLimiterRegistry with a custom RateLimiterConfig.

// Create a custom configuration for a RateLimiter RateLimiterConfig config = RateLimiterConfig.custom() .timeoutDuration(TIMEOUT) .limitRefreshPeriod(REFRESH_PERIOD) .limitForPeriod(LIMIT) .build(); // Create a RateLimiterRegistry with a custom global configuration RateLimiterRegistry registry = RateLimiterRegistry.of(config);

Override the RegistryStore

You can override the im-memory RegistryStore by a custom implementation. For example, if you want to use a Cache which removes unused instances after a certain period of time.

RateLimiterRegistry rateLimiterRegistry = RateLimiterRegistry.custom() .withRegistryStore(new CacheRateLimiterRegistryStore()) .build();