CircuitBreakerConfig
Configuration for a CircuitBreaker.
This class provides a flexible way to configure the behavior of a CircuitBreaker instance using a builder-style pattern.
Example:
val config = CircuitBreakerConfig().apply {
failureThreshold = 10
timeout = 30.seconds
onStateChange = { newState -> println("Circuit state changed to $newState") }
}
val circuitBreaker = CircuitBreaker.create(config)Properties
When non-null, enables failure-rate mode using a count-based sliding window. The circuit opens when the failure rate (as a percentage, 0.0–100.0) computed over the last minimumNumberOfCalls outcomes meets or exceeds this value. The rate is not evaluated until minimumNumberOfCalls have been recorded. Cannot be combined with slidingWindow; setting both throws IllegalArgumentException. Defaults to null (disabled).
Number of failures required to open the circuit from CLOSED.
The maximum number of concurrent calls allowed when the circuit is in the HALF_OPEN state. This is to test if the downstream service has recovered. Additional calls beyond this limit will be rejected. Defaults to 3.
Minimum number of calls that must be recorded before failureRateThreshold is evaluated. Acts as both the minimum-calls guard and the ring-buffer size. Defaults to 10. Only meaningful when failureRateThreshold is non-null.
Invoked when the circuit state changes. Receives the new state only. When the policy is built via com.santimattius.resilient.composition.resilient, telemetry events (ResilientEvent.CircuitStateChanged) receive both the previous and new state.
Optional predicate evaluated after the block returns without throwing.
When null (default), failureThreshold counts consecutive failures in CLOSED. When set to a positive duration, failures in CLOSED are recorded with a timestamp; entries older than this window are discarded. The circuit opens when at least failureThreshold failures fall inside the window. Success in CLOSED only prunes expired failures (it does not clear recent failures). HALF_OPEN and OPEN behavior is unchanged.