Java Code Examples for io.github.resilience4j.ratelimiter.RateLimiterConfig#custom()

The following examples show how to use io.github.resilience4j.ratelimiter.RateLimiterConfig#custom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RateLimiterRegistry.java    From spring-cloud-formula with Apache License 2.0 6 votes vote down vote up
private static RateLimiterConfig createRateLimiterConfig(FormulaRateLimiterConfig rateLimiterConfig) {
    if (rateLimiterConfig == null) {
        return null;
    }

    RateLimiterConfig.Builder rateLimiterConfigBuilder = RateLimiterConfig.custom();

    if (rateLimiterConfig.getThreshold() != null) {
        rateLimiterConfigBuilder.limitForPeriod(rateLimiterConfig.getThreshold());
    }

    // rateLimiterConfigBuilder.limitRefreshPeriod(Duration.ofMillis(1000)); // default 1s

    if (rateLimiterConfig.getTimeoutInMillis() != null) { // default 0
        rateLimiterConfigBuilder.timeoutDuration(Duration.ofMillis(rateLimiterConfig.getTimeoutInMillis()));
    }

    return rateLimiterConfigBuilder.build();
}
 
Example 2
Source File: TokenBucketRateLimiterTest.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    limitsForPeriod = 2;
    RateLimiterConfig.Builder rateLimiterConfigBuilder = RateLimiterConfig.custom();
    rateLimiterConfigBuilder.limitForPeriod(limitsForPeriod);
    rateLimiterConfig = rateLimiterConfigBuilder.build();
}