Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ProductService
{
private readonly HttpClient _httpClient;
private readonly AsyncCircuitBreakerPolicy _circuitBreakerPolicy;
public ProductService()
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:5000/");
_circuitBreakerPolicy = Policy.Handle<HttpRequestException>()
.CircuitBreakerAsync(exceptionsAllowedBeforeBreaking: 2,
durationOfBreak: TimeSpan.FromMinutes(1));
}
public async Task<string> GetSample()
{
return await _circuitBreakerPolicy.ExecuteAsync<string>(async () =>
{
return await _httpClient.GetStringAsync("api/business");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.