ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.31k stars 1.63k forks source link

Use Polly v8 syntax #1875

Closed RaynaldM closed 6 months ago

RaynaldM commented 8 months ago

Use Polly 8's specific syntax to define resiliencePipelines (vs. PollyPolicies)

Polly v8 introduces the concept of resilience pipelines, a powerful tool that blends one or more resilience strategies. This new API foundation echoes the Policy Wrap of previous versions but is now integrated seamlessly into the core API. All strategies start with a pipeline.

in v7, we written

// Create and use the IAsyncPolicy
IAsyncPolicy asyncPolicy = Policy
    .Handle<Exception>()
    .WaitAndRetryAsync(3, _ => TimeSpan.FromSeconds(1));

in v8, it becomes

// Use the ResiliencePipelineBuilder to start building the resilience pipeline
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions
    {
        ShouldHandle = new PredicateBuilder().Handle<Exception>(),
        Delay = TimeSpan.FromSeconds(1),
        MaxRetryAttempts = 3,
        BackoffType = DelayBackoffType.Constant
    })
    .Build(); // After all necessary strategies are added, call Build() to create the pipeline.
raman-m commented 8 months ago

Wow! Good to know about new Polly 8 features... I see you are big fan of Polly 😉

raman-m commented 8 months ago

You need to choose release number: Annual (aka 24.0) or Jan'24 (aka 24.1) We can include this upgrade even in Annual'23: I see the feature branch, seems you're going to create a PR soon... Finally you need to choose release number to include this feature in. OK?

RaynaldM commented 8 months ago

In 24.1

raman-m commented 6 months ago

@RaynaldM commented on Jan 5:

In 24.1

No. It will belong to version 23.1 actually. See the milestone version and our Slack channels!