Phase 4 Setup - Adding Chaos!
This commit is contained in:
@@ -28,6 +28,24 @@ services.AddDbContext<AppDbContext>(optionsBuilder =>
|
|||||||
});
|
});
|
||||||
var httpClientBuilder = services.AddHttpClient<JsonPlaceholderClient>();
|
var httpClientBuilder = services.AddHttpClient<JsonPlaceholderClient>();
|
||||||
|
|
||||||
|
#region Exercise Phase 4
|
||||||
|
|
||||||
|
httpClientBuilder.AddResilienceHandler("chaos", configure =>
|
||||||
|
{
|
||||||
|
// Simulate network chaos by adding latency and random errors.
|
||||||
|
configure
|
||||||
|
.AddChaosLatency(0.10, TimeSpan.FromSeconds(3))
|
||||||
|
.AddChaosOutcome(0.15, () => new HttpResponseMessage(System.Net.HttpStatusCode.BadGateway))
|
||||||
|
.AddChaosOutcome(0.20, () => new HttpResponseMessage(System.Net.HttpStatusCode.ServiceUnavailable))
|
||||||
|
.AddChaosOutcome(0.10, () =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(2)); // Delay the error response, as it would likely happen with a 504.
|
||||||
|
return new HttpResponseMessage(System.Net.HttpStatusCode.GatewayTimeout);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(); // Swagger UI is available at http://localhost:8080/swagger/index.html
|
app.UseSwaggerUI(); // Swagger UI is available at http://localhost:8080/swagger/index.html
|
||||||
|
|||||||
Reference in New Issue
Block a user