Pawel Lukasik
.net dev
don't worry, be happy
...there was a chaos.
...there was an order
Proin ac dolor nec nisi lobortis venenatis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean nec elementum est.
- Jarek & Paweł
- OstraPiła podcast - 97 eps
- Ostra Uczy > 50 live streams
var retryStrategyOptions = new RetryStrategyOptions
{
ShouldHandle = (_) => ValueTask.FromResult<bool>(true),
};
var pipeline = new ResiliencePipelineBuilder()
.AddRetry(retryStrategyOptions)
.Build();
bool success = false;
pipeline.Execute(async () =>
{
WriteLine($"Fetching {DateTime.Now}");
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl");
success = r.IsSuccessStatusCode;
});
Hello, World!
Trying to fetch data from network 26.04.2024 00:19:13
Trying to fetch data from network 26.04.2024 00:19:15
Trying to fetch data from network 26.04.2024 00:19:17
Trying to fetch data from network 26.04.2024 00:19:19
Success: False
var o = new RetryStrategyOptions
{
ShouldHandle = (_) => ValueTask.FromResult<bool>(true),
};
var pipeline = new ResiliencePipelineBuilder()
.AddCircuitBreaker(o)
.Build();
while (true)
pipeline.Execute(async () =>
{
Console.WriteLine($"Fetching {DateTime.Now}");
var c = new HttpClient();
var r = await c.GetAsync("http://ooops");
success = response.IsSuccessStatusCode;
});
Trying to fetch data from network 26.04.2024 00:16:37
... 100 times later
Trying to fetch data from network 26.04.2024 00:16:37
Unhandled exception. Polly.CircuitBreaker.BrokenCircuitException: The circuit is now open and is not allowing calls.
at Polly.Outcome`1.GetResultOrRethrow()
at Polly.ResiliencePipeline.Execute[TResult](Func`1 callback)
at Program.<Main>$(String[] args) in Program.cs:line 25
By Pawel Lukasik