Skip to content

Instantly share code, notes, and snippets.

Avatar

Maicon C Pereira maiconcp

View GitHub Profile
View Polly_Circuit_Breaker_Output
Call 1: System.Net.Http.HttpRequestException
Call 2: System.Net.Http.HttpRequestException
Call 3: Polly.CircuitBreaker.BrokenCircuitException
Call 4: Polly.CircuitBreaker.BrokenCircuitException
Call 5: Polly.CircuitBreaker.BrokenCircuitException
View Polly_Circuit_Breaker_Client.cs
public class Client
{
private readonly ProductService _productService;
public Client()
{
_productService = new ProductService();
}
private string Call()
View Polly_Circuit_Breaker_ProductService.cs
public class ProductService
{
private readonly HttpClient _httpClient;
private readonly AsyncCircuitBreakerPolicy _circuitBreakerPolicy;
public ProductService()
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:5000/");
View Polly_Retry.cs
// Retry a specified number of times, using a function to
// calculate the duration to wait between retries based on
// the current retry attempt (allows for exponential backoff)
// In this case will wait for
// 2 ^ 1 = 2 seconds then
// 2 ^ 2 = 4 seconds then
// 2 ^ 3 = 8 seconds then
// 2 ^ 4 = 16 seconds then
// 2 ^ 5 = 32 seconds
Policy
You can’t perform that action at this time.