I do like Polly.NET, the “resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner”(quoted from the website).
One of the nice things you can do in Polly is combining multiple policies to achieve more complex functionality:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fallback.Execute(() => waitAndRetry.Execute(() => breaker.Execute(action))); |
This works but requires some ugly nesting. A better approach I learned at NDC was through PolicyWrap:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Policy.Wrap(fallback, waitAndRetry, breaker).Execute(action); |
More information here: https://github.com/App-vNext/Polly/wiki/PolicyWrap