Skip to content

Two rate limiters in same pipeline #2341

Answered by martincostello
lonix1 asked this question in Q&A
Discussion options

You must be logged in to vote

Something like this should work for you:

var args = Array.Empty<string>();
var cancellationToken = CancellationToken.None;
var key = "partition-key";

var first = PartitionedRateLimiter.Create<ResilienceContext, string>((context) =>
{
    return RateLimitPartition.GetFixedWindowLimiter(
        key,
        (_) => new() { /* ... */ });
});

var second = PartitionedRateLimiter.Create<ResilienceContext, string>((context) =>
{
    return RateLimitPartition.GetFixedWindowLimiter(
        key,
        (_) => new() { /* ... */ });
});

var chainedRateLimiter = PartitionedRateLimiter.CreateChained(first, second);

var resiliencePipeline = new ResiliencePipelineBuilder()
    .AddRateLimiter(new R…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@lonix1
Comment options

@martincostello
Comment options

Answer selected by lonix1
@lonix1
Comment options

@lonix1
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
2 participants