I have method which returns IAsyncPolicy<HttpResponseMessage>
and it has 2 or more policies along with CircuitBreaker
and part of my DI.
Now in my implementation class I added one extra fallbackPolicy to handle BrokenCircuitException
and wrap it with IAsyncPolicy<HttpResponseMessage>
(AsyncPolicy)
Now I did my custom method implementation within DoWork()
method, Great!!! Thanks to FallbackAsync
policy where I'm catching BrokenCircuitException
exception, means when circuit is open.
var fallbackPolicy = Policy<HttpResponseMessage>
.Handle<BrokenCircuitException>()
.FallbackAsync(async (cancellationToken) => await DoWork()
.ConfigureAwait(false));
var policyWrap = fallbackPolicy.WrapAsync(AsyncPolicy);
// Send message to service
var response = await policyWrap.ExecuteAsync(() => HttpClient.PostAsync(...
Now question is, do we have any policy or a way to know when the circuit is close and I can write my own method implementation?
In my shared policy where I have CircuitBreaker` too which I wrote as in DI area have below signature, but I can't write my custom method implementation here.
onReset: () =>
{
Trace.TraceInformation("Web API Close");
},