Last active
May 1, 2019 19:35
-
-
Save maiconcp/d1b1c5355bfc41ac3a108adac7b4d14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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