We're using the latest Polly to handle our retry and circuit breaker policies for interacting with three APIs.
Basic flow is:
A) Read data from Product Catalogue (API)
B) Get Unique Merchant Token (API)
C) Update Merchant Catalogue (with new item) (API)
Due to the load on Merchant Catalogue API (third party, can't work around this yet!) we get bounced sometimes. Polly is configured to nicely retry this if it fails and circuit breaker pattern style, back off.
We realised that it was being tripped consistently because our Merchant Token was marked as invalid even though the server spat the dummy - the third party marks a token used even on error.
Reading this article which is what we based our solution on initially, we are thinking using the context to reload/refresh the auth token. However I'm a bit confused how I can have a policy that refreshes that token when that logic is not in the wiring up (startup) and instead in the handler that runs the policy.
var authMerchTokenPolicy = Policy<HttpResponseMessage>
.HandleResult(r => r.StatusCode == 500)
.RetryAsync(1, onRetryAsync: async (ex, i, context) => await RefreshMerchantAuthorization(context["httpClient"]));
Is the above example stating that I implement RefreshMerchantAuthorization
in the startup class?
I haven't seen a concrete example which is where the confusion lies - and the original developer has since left who wrote this (ironically named Paulie!)