Package discord4j.rest.request
Class BucketGlobalRateLimiter
java.lang.Object
discord4j.rest.request.BucketGlobalRateLimiter
- All Implemented Interfaces:
GlobalRateLimiter
An implementation of
GlobalRateLimiter that uses a RateLimitOperator coordinate requests, injecting
an additional delay if a source trips the limiter early through rateLimitFor(Duration).-
Method Summary
Modifier and TypeMethodDescriptionstatic BucketGlobalRateLimitercreate()Creates a new global rate limiter of 50 requests per second usingSchedulers.parallel()to inject delays.static BucketGlobalRateLimiterCreates a new global rate limiter with the given parameters.Returns theDurationremaining until the current global rate limit is completed.rateLimitFor(Duration duration) Sets a new rate limit that will be applied to every operation performed usingGlobalRateLimiter.withLimiter(Publisher).<T> Flux<T>withLimiter(Publisher<T> stage) Provides a scope to perform reactive operations under this global rate limiter.
-
Method Details
-
create
Creates a new global rate limiter of 50 requests per second usingSchedulers.parallel()to inject delays.- Returns:
- a
BucketGlobalRateLimiterwith default parameters
-
create
public static BucketGlobalRateLimiter create(int capacity, Duration refillPeriod, Scheduler delayScheduler) Creates a new global rate limiter with the given parameters. Be aware that modifying these parameters can lead your bot hitting 429 TOO MANY REQUESTS errors.- Parameters:
capacity- the number of requests that can be performed in the givenrefillPeriodrefillPeriod- theDurationbefore refilling request permitsdelayScheduler- theSchedulerused to inject delays- Returns:
- a
BucketGlobalRateLimiterwith the given parameters.
-
rateLimitFor
Description copied from interface:GlobalRateLimiterSets a new rate limit that will be applied to every operation performed usingGlobalRateLimiter.withLimiter(Publisher).- Specified by:
rateLimitForin interfaceGlobalRateLimiter- Parameters:
duration- theDurationevery new operation should wait before being used
-
getRemaining
Description copied from interface:GlobalRateLimiterReturns theDurationremaining until the current global rate limit is completed. Can be negative or zero if there is no currently active global rate limit.- Specified by:
getRemainingin interfaceGlobalRateLimiter- Returns:
- a positive
Durationindicating the remaining time a global rate limit is being applied. Zero or negative if no global rate limit is currently active.
-
withLimiter
Description copied from interface:GlobalRateLimiterProvides a scope to perform reactive operations under this global rate limiter. Limiter resources are acquired on subscription and released when the given stage is cancelled, has completed or has been terminated with an error.- Specified by:
withLimiterin interfaceGlobalRateLimiter- Type Parameters:
T- the type of the stage supplier- Parameters:
stage- aPublisherthat will manage this global rate limiter resources- Returns:
- a
Fluxwhere each subscription represents acquiring a rate limiter resource
-