Skip to content

Determine which limiter rejects when using both ConcurrenceLimiter and RateLimiter #1777

Answered by eisendle
eisendle asked this question in Q&A
Discussion options

You must be logged in to vote

Found a solution:

In the OnRejected callback, set a ResilienceContext property indicating the rate limit has been hit. If the pipeline throws a RateLimiterRejectedException check the ResilienceContext if the property exists. If it exists, the rate limit has been hit, otherwise the concurrency limit has been hit.

Example:

private static readonly ResiliencePropertyKey<string> UserProperty = new("UserName");
private static readonly ResiliencePropertyKey<bool> RateLimitHitProperty = new("RateLimitHit");
private readonly ResiliencePipeline _resiliencePipeline = CreateResiliencePipeline(options);

private static ResiliencePipeline CreateResiliencePipeline(IOptions<MyOptions> options, ILogger lo…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@martintmk
Comment options

@lonix1
Comment options

Answer selected by eisendle
Comment options

You must be logged in to vote
1 reply
@eisendle
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants