My question is how to implement (configure) throttlig using resilience4j library. I tried to use RateLimiter with next configuration:
RateLimiter rateLimiter = RateLimiterRegistry.of(
RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofSeconds(10))
.limitForPeriod(1)
.timeoutDuration(Duration.ofSeconds(5))
.build()
).rateLimiter("default");
Runnable ratedCall = RateLimiter.decorateRunnable(rateLimiter, () -> { /*business logic here*/ });
// and then
try {
ratedCall.run();
} catch (Exception e) {
LOG.warn(e);
}
but it does not prevent (ignore) subsequent method calls. What I need to achieve is that my particular method cannot be invoked more that once in 10 seconds regardless of any possible exceptions.
Please, advice!
Thanx!