CircuitBreakerStrategyOptions
Configures the circuit breaker resilience strategy.How It Works
The circuit breaks if, within any time-slice of durationSamplingDuration, the proportion of actions resulting in a handled exception exceeds FailureRatio, provided also that the number of actions through the circuit is at least MinimumThroughput.
The circuit stays broken for the BreakDuration. Any attempt to execute while broken immediately throws a BrokenCircuitException.
Properties
The failure-to-success ratio at which the circuit will break.
- Must be between 0 and 1 (inclusive)
- Example: 0.5 means the circuit breaks if 50% or more of actions fail
- Default is 0.1 (10%)
The minimum throughput required for statistics to be considered significant.This many actions or more must pass through the circuit in the time-slice for the circuit breaker to come into action.
- Must be 2 or greater
- Default is 100
The duration of the sampling window over which failure ratios are assessed.
- Must be greater than 0.5 seconds
- Default is 30 seconds
The duration the circuit will stay open before resetting.
- Must be greater than 0.5 seconds
- Default is 5 seconds
An optional delegate to dynamically generate the break duration.Allows for advanced scenarios like exponentially increasing break durations.
A predicate that determines whether an outcome should be handled by the circuit breaker.Default: Handles any exception except
OperationCanceledException.Event raised when the circuit resets to a
Closed state.Note: These events are invoked with eventual consistency. Use CircuitBreakerStateProvider for up-to-date state.Event raised when the circuit transitions to an
Open state.Note: These events are invoked with eventual consistency.Event raised when the circuit transitions to a
HalfOpen state.Note: These events are invoked with eventual consistency.Manual control for the circuit breaker.Allows programmatic control to isolate or close the circuit.
State provider for the circuit breaker.Allows monitoring the current state of the circuit.
Extension Methods
Add circuit breaker strategies to a resilience pipeline:Circuit States
The circuit breaker can be in one of three states:- Closed: Normal operation, requests flow through
- Open: Circuit is broken, requests are immediately rejected
- HalfOpen: Testing if the circuit should close after the break duration