Pawel Lukasik
.net dev
czyli Andrzeju nie denerwuj się!
...był chaos.
...był porządek
my widziani oczami eJaJ 🤦♂️
var retryStrategyOptions = new RetryStrategyOptions
{
ShouldHandle = _
=> ValueTask.FromResult(true),
};
var pipeline = new ResiliencePipelineBuilder()
.AddRetry(retryStrategyOptions)
.Build();
await pipeline.ExecuteAsync(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
});
var fallbackStrategyOptions = new FallbackStrategyOptions<HttpResponseMessage>
{
FallbackAction = _ => Outcome.FromResultAsValueTask(
new HttpResponseMessage(HttpStatusCode.Gone)),
};
var pipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddFallback(fallbackStrategyOptions)
.Build();
await pipeline.ExecuteAsync<HttpResponseMessage>(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
return r;
});
var hedgingStrategyOptions = new HedgingStrategyOptions<HttpResponseMessage>
{
Delay = TimeSpan.FromSeconds(5),
ActionGenerator = static _ => () =>
Outcome.FromResultAsValueTask(
new HttpResponseMessage(HttpStatusCode.Processing)),
};
var pipeline = new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddHedging(hedgingStrategyOptions)
.Build();
await pipeline.ExecuteAsync<HttpResponseMessage>(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
return r;
});
var timeoutStrategyOptions = new TimeoutStrategyOptions
{
Timeout = TimeSpan.FromSeconds(10),
};
var pipeline =
new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddTimeout(timeoutStrategyOptions)
.Build();
await pipeline.ExecuteAsync<HttpResponseMessage>(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
return r;
});
var pipeline = new ResiliencePipelineBuilder()
.AddChaosFault(new ChaosFaultStrategyOptions
{
FaultGenerator = _ =>
new ValueTask<Exception?>(new Exception()),
InjectionRate = 0.2
})
.Build();
await pipeline.ExecuteAsync(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
});
var pipeline =
new ResiliencePipelineBuilder<HttpResponseMessage>()
.AddChaosOutcome(
new ChaosOutcomeStrategyOptions<HttpResponseMessage>()
{
InjectionRate = 0.2,
OutcomeGenerator = _ =>
new ValueTask<HttpResponseMessage>(
new HttpResponseMessage(HttpStatusCode.Ambiguous)),
}).Build();
await pipeline.ExecuteAsync<HttpResponseMessage>(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
return r;
});
var pipeline = new ResiliencePipelineBuilder()
.AddChaosLatency(new ChaosLatencyStrategyOptions()
{
InjectionRate = 0.1,
Latency = TimeSpan.FromSeconds(3)
})
.Build();
await pipeline.ExecuteAsync(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
});
var pipeline = new ResiliencePipelineBuilder()
.AddChaosBehavior(new ChaosBehaviorStrategyOptions
{
InjectionRate = 0.3,
BehaviorGenerator = _ => DoEpicShit()
})
.Build();
await pipeline.ExecuteAsync(async token =>
{
var c = new HttpClient();
var r = await c.GetAsync("http://ooops.pl", token);
r.EnsureSuccessStatusCode();
});
- wymaga Keyed services z .NET 8
- kontener DI z .NET 8 jest OK, ale np. Lamar z Wolverine'a nie wspiera 🤷♂️
.ConfigureTelemetry(
new TelemetryOptions
{
LoggerFactory =
LoggerFactory.Create(
builder => builder.AddConsole()),
TelemetryListeners =
{ new MyTelemetryListener() }
})
- Jarek & Paweł
- OstraPiła podcast - 97 odc
- Ostra Uczy > 50 live'ów
* - używaliśmy wersji v7
Like & subscribe
@ostrapila
@j_stadnicki
@pawel_lukasik
Feedback!
By Pawel Lukasik