public class BucketGlobalRateLimiter extends Object implements GlobalRateLimiter
GlobalRateLimiter that uses a RateLimitOperator coordinate requests, injecting
an additional delay if a source trips the limiter early through rateLimitFor(Duration).| Modifier and Type | Method and Description |
|---|---|
static BucketGlobalRateLimiter |
create()
Creates a new global rate limiter of 50 requests per second using
Schedulers.parallel() to inject delays. |
static BucketGlobalRateLimiter |
create(int capacity,
Duration refillPeriod,
Scheduler delayScheduler)
Creates a new global rate limiter with the given parameters.
|
Mono<Duration> |
getRemaining()
Returns the
Duration remaining until the current global rate limit is completed. |
Mono<Void> |
rateLimitFor(Duration duration)
Sets a new rate limit that will be applied to every operation performed using
GlobalRateLimiter.withLimiter(Publisher). |
<T> Flux<T> |
withLimiter(Publisher<T> stage)
Provides a scope to perform reactive operations under this global rate limiter.
|
public static BucketGlobalRateLimiter create()
Schedulers.parallel() to inject delays.create in interface GlobalRateLimiterBucketGlobalRateLimiter with default parameterspublic static BucketGlobalRateLimiter create(int capacity, Duration refillPeriod, Scheduler delayScheduler)
capacity - the number of requests that can be performed in the given refillPeriodrefillPeriod - the Duration before refilling request permitsdelayScheduler - the Scheduler used to inject delaysBucketGlobalRateLimiter with the given parameters.public Mono<Void> rateLimitFor(Duration duration)
GlobalRateLimiterGlobalRateLimiter.withLimiter(Publisher).rateLimitFor in interface GlobalRateLimiterduration - the Duration every new operation should wait before being usedpublic Mono<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)
GlobalRateLimiterwithLimiter in interface GlobalRateLimiterT - the type of the stage supplierstage - a Publisher that will manage this global rate limiter resourcesFlux where each subscription represents acquiring a rate limiter resource