1

I'm using the Polly along with Flurl to perform GET and POST operations to a variety of endpoints.

One of the operations that is done is a POST to ElasticSearch. We have serveral ES clusters, and what I would like to do is this:

  • Policy.TimeoutAsync to set a timeout
  • Policy.RetryAsync to retry on some failures
  • Policy.FallbackAsync to try the whole thing again pointing to a different cluster
  • Policy.CircuitBreakerAsync to stop communication attempts if all the fallbacks fail

The Timeout, Retry and CircuitBreaker policies have been set up, they work as advertised, but I cannot figure out how to make Fallback work the way I want - all the examples I see illustrate how to create a 'fake' reply rather than talk to an alternative server.

Can this be done through Polly (or Flurl)? My fallback is hand-coded looping and logic for the Fallback and CircuitBreaker policies.

Marc Bernier
  • 2,928
  • 27
  • 45
  • Polly's retry logic executes the exact same operation several times depending on the configuration and conditions. So, by default you can't change the url. In the following two SO topics I've already demonstrated several approaches how you use different urls during retries: [1](https://stackoverflow.com/a/66777212/13268855), [2](https://stackoverflow.com/a/62086579/13268855) – Peter Csala Jan 04 '22 at 08:03
  • Did my suggested solutions answer your question or do you need further information? – Peter Csala Jan 06 '22 at 14:54
  • 1
    The iterator was very helpful. Still working it out, but my so-far working solution is that I use a Retry that is retries * domains.Count, and on the retry event, I bump the iterator when retry % retries == 0. When the retries are exhausted, it jumps to the next policy (circuit breaker). When the circuitbreakerreset policy trips, I reset the iterator. – Marc Bernier Jan 06 '22 at 19:41
  • 1
    When I have something working, I'll post a full solution here, it was a little different than the answers you pointed to, in that I wanted to retry each domain a few times and also when I land on a good domain, I want to stick with that one (until it fails). – Marc Bernier Jan 06 '22 at 19:43
  • Thanks for the extra information. Depending on how many fallback domains do you have it might make sense to have a separate proxy for each rather than replacing the url. I know you are using Flurl, not HttpClient but for inspiration [this thread](https://stackoverflow.com/a/69539936/13268855) might be useful as well. – Peter Csala Jan 06 '22 at 20:10

0 Answers0