The purpose of this repo is to help you run example code from this article: https://makolyte.com/csharp-how-to-make-concurrent-requests-with-httpclient/
There are two apps:
- Client-side console app. This sends concurrent requests to the web API.
- Web API. This has one endpoint (GET /RandomNumber) and listens on https://localhost:12345/.
The service stub runs on https://localhost:12345/.
- Start the ASP.NET web API project in /WebApi/.
- Run the console app in /client/
You'll see it start sending concurrent requests. The max concurrency is set to 4.
By default, there are two types of responses:
- A random number.
- An error response 25% of the time. This is test the client's resiliency!
You'll see a random request fail and trip the circuit. After that, the remaining requests will fail.
The simplest way to induce timeouts on the client-side is to put a delay in the Web API. For example:
await Task.Delay(-1, HttpContext.RequestAborted)
Another way is to use toxiproxy. See here: https://makolyte.com/how-to-use-toxiproxy-to-verify-your-code-can-handle-timeouts-and-unavailable-endpoints/