3

I need to see is a circuit break is closed but my polices are in a policy wrap. How can find the CircuitBreakerPolicy (one or more) in the wrap? Is there a better way to know is any breaker is open for a given policy?

Don Chambers
  • 3,798
  • 9
  • 33
  • 74

1 Answers1

2

As per the Polly documentation:

For example:

var breaker = wrap.GetPolicy<CircuitBreakerPolicy>();
var state = breaker.CircuitState;

or:

var breaker = wrap.GetPolicy<CircuitBreakerPolicy>(p => p.PolicyKey == "SomeKey");

or:

IEnumerable<CircuitBreakerPolicy> breakers = wrap.GetPolicies<CircuitBreakerPolicy>();

CircuitBreakerPolicy (as the type to obtain) is only an example in the above. Substitute with the specific type you need:

  • CircuitBreakerPolicy
  • AsyncCircuitBreakerPolicy
  • AsyncCircuitBreakerPolicy<HttpResponseMessage>

(or whatever)

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
mountain traveller
  • 7,591
  • 33
  • 38