This repository provides sample implementations of using the Polly library in a .NET application.
The intent of this project is to help newcomers kick-start the use of Polly within their own projects.
The samples demonstrate the policies in action, against faulting endpoints.
The solution contains three applications and one class library:
PollyTestWebApi
: This application is a web API with several endpoints. (Further information)PollyDemos
: This library contains the Polly demos. (Further information)PollyTestClientConsole
: This application provides a CLI to walk through the demos. (Further information)PollyTestClientWpf
: This application provides a GUI to walk through the demos. (Further information)
flowchart LR
console{{PollyTestClientConsole}}
wpf{{PollyTestClientWPF}}
lib>PollyDemos]
api[/PollyTestWebApi\]
console -- uses --> lib
wpf -- uses --> lib
lib -- invokes --> api
- The demos run against an example 'faulting server'.
- To simulate failure, the dummy server rejects more than 3 calls in any five-second period.
- Be sure to read the
<summary>
at the top of each demo.- This explains the intent of that demo, and what resilience it adds to its handling of the calls to the 'faulting server'.
- Sometimes the
<summary>
also highlights what this demo doesn't achieve, which is often picked up in the following demo. - Explore the demos in sequence for best understanding.
# | Description | Link |
---|---|---|
00 | No strategy | Code |
01 | Retry N times | Code |
02 | Wait and retry N times | Code |
03 | Wait and retry N times, N big enough to guarantee success | Code |
04 | Wait and retry forever | Code |
05 | Wait and retry with exponential back-off | Code |
06 | Wait and retry nesting circuit breaker | Code |
07 | Wait and retry chaining with circuit breaker by using Pipeline | Code |
08 | Fallback, Retry, and CircuitBreaker in a Pipeline | Code |
09 | Fallback, Timeout, and Retry in a Pipeline | Code |
10 | Without isolation: Faulting calls swamp resources, also prevent good calls |
Code |
11 | With isolation: Faulting calls separated, do not swamp resources, good calls still succeed |
Code |
12 | Hedging in latency mode | Code |
13 | Hedging in fallback mode: retry only | Code |
14 | Hedging in fallback mode: retry with fallback | Code |
15 | Hedging in parallel mode | Code |
16 | Entity Framework with retry N times | Code |
- For any questions about the operation of the demos, ask on this repo with an issue.
- For any questions about Polly, ask in the Polly repository.
- For full Polly syntax, see Polly repository and the Polly documentation.
View the slides presented at NDC, DevIntersections and other conferences.
You are welcome to use and adapt this presentation for not-for-profit presentations of Polly to co-workers, user groups and similar, subject to the condition that references to the .NET Foundation, App-vNext and the individual members of the Polly team are retained.