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?
As per the Polly documentation:
The circuit-breaker exposes its state as breaker.CircuitState
.
PolicyWrap
provides a variety of methods allowing you to obtain the policies in a wrap.
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)