Skip to content
This repository was archived by the owner on Feb 3, 2020. It is now read-only.

Repository files navigation

Steps to include Polly in project using Curcuit Breaker pattern:

  1. Have your project grab the ASPNET Core 2.1 packages from nuget. You'll typically need the AspNetCore metapackage, and the extension package Microsoft.Extensions.Http.Polly.

  2. Configure a client with Polly policies, in Startup. Insert this two private methods:

privatestaticIAsyncPolicy<HttpResponseMessage>GetRetryPolicy(){returnHttpPolicyExtensions.HandleTransientHttpError().OrResult(msg =>msg.StatusCode==System.Net.HttpStatusCode.NotFound).WaitAndRetryAsync(6, retryAttempt =>TimeSpan.FromSeconds(Math.Pow(2,retryAttempt)));}privatestaticIAsyncPolicy<HttpResponseMessage>GetCircuitBreakerPolicy(){returnHttpPolicyExtensions.HandleTransientHttpError().CircuitBreakerAsync(5,TimeSpan.FromSeconds(30));}
  1. In your standard Startup.ConfigureServices(...) method, start by configuring a named client as below:
services.AddHttpClient("ProfileHttpClient").AddPolicyHandler(GetRetryPolicy()).AddPolicyHandler(GetCircuitBreakerPolicy());whereProfileHttpClient-your HTTP client implementation

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages