public class SemaphoreGlobalRateLimiter extends Object implements GlobalRateLimiter
GlobalRateLimiter that uses fair Semaphore instances as implementation. Can be configured with the
amount of permits it allows before blocking further acquire attempts until permits are released.| Constructor and Description |
|---|
SemaphoreGlobalRateLimiter(int parallelism)
Creates a new global rate limiter with the specified parallelism level.
|
| Modifier and Type | Method and Description |
|---|---|
Duration |
getRemaining()
Returns the
Duration remaining until the current global rate limit is completed. |
void |
rateLimitFor(Duration duration)
Sets a new rate limit that will be applied to every new resource acquired.
|
<T> Flux<T> |
withLimiter(Publisher<T> stage)
Provides a scope to perform reactive operations under this limiter resources.
|
public SemaphoreGlobalRateLimiter(int parallelism)
parallelism - the maximum number of requests that this limiter will allow in parallelpublic void rateLimitFor(Duration duration)
rateLimitFor in interface GlobalRateLimiterduration - the Duration every new acquired resource should wait before being usedpublic Duration getRemaining()
GlobalRateLimiterDuration remaining until the current global rate limit is completed. Can be negative or
zero if there is no currently active global rate limit.getRemaining in interface GlobalRateLimiterDuration indicating the remaining time a global rate limit is being applied. Zero
or negative if no global rate limit is currently active.public <T> Flux<T> withLimiter(Publisher<T> stage)
withLimiter in interface GlobalRateLimiterT - the type of the stage supplierstage - a Mono that will manage this limiter resourcesMono where each subscription represents acquiring a rate limiter resource