0

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");
                    },
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
user584018
  • 10,186
  • 15
  • 74
  • 160
  • Please provide more information on what is preventing you writing your custom method implementation in the `onReset` delegate hook. – mountain traveller Nov 20 '19 at 08:02
  • My method is in different class, how to hook that method here? – user584018 Nov 20 '19 at 08:47
  • Can it be made a static method? Or does the method need to be executed on an instance of that other class? Is the method to be executed during `onReset` the same for all uses of the circuit-breaker policy instance? Or is it intended to differ at different call sites consuming the circuit-breaker policy instance? What is the overall goal? – mountain traveller Nov 20 '19 at 18:20

0 Answers0