Polly.RateLimiting package provides rate limiting capabilities using the .NET System.Threading.RateLimiting library, allowing you to control the rate of executions through your resilience pipelines.
Installation
Extension Methods
AddRateLimiter
Adds a rate limiter to the resilience pipeline.TBuilder
required
The builder instance
RateLimiterStrategyOptions
required
The rate limiter strategy options
AddRateLimiter (with RateLimiter instance)
Adds a rate limiter instance directly to the pipeline.TBuilder
required
The builder instance
RateLimiter
required
The rate limiter to use
AddConcurrencyLimiter
Adds a concurrency limiter to the pipeline.TBuilder
required
The builder instance
int
required
Maximum number of permits that can be leased concurrently
int
default:"0"
Maximum number of permits that can be queued concurrently
AddConcurrencyLimiter (with options)
Adds a concurrency limiter with detailed options.TBuilder
required
The builder instance
ConcurrencyLimiterOptions
required
The concurrency limiter options
Configuration Classes
RateLimiterStrategyOptions
Options for configuring the rate limiter strategy.Properties
RateLimiter A delegate that produces aRateLimitLease. If null, the strategy will use a ConcurrencyLimiter created with DefaultRateLimiterOptions.
- Type:
Func<RateLimiterArguments, ValueTask<RateLimitLease>>? - Default:
null
RateLimiter is null.
- Type:
ConcurrencyLimiterOptions - Default:
PermitLimit = 1000, QueueLimit = 0
- Type:
Func<OnRateLimiterRejectedArguments, ValueTask>? - Default:
null
RateLimiterArguments
Arguments passed to the rate limiter delegate.OnRateLimiterRejectedArguments
Arguments passed to theOnRejected callback.
Properties
Context The resilience context associated with the execution.- Type:
ResilienceContext
- Type:
RateLimitLease
Exceptions
RateLimiterRejectedException
Exception thrown when a rate limiter rejects an execution.Properties
RetryAfter The amount of time to wait before retrying again. Retrieved from theRateLimitLease metadata.
- Type:
TimeSpan? - Default:
null