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?
Asked
Active
Viewed 280 times
1 Answers
2
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)

Peter Csala
- 17,736
- 16
- 35
- 75

mountain traveller
- 7,591
- 33
- 38
-
thanks. That pesky documentation. The answer is always lurking in there. – Don Chambers Mar 01 '19 at 14:06