The circuitBreaker event handler
The circuit breaker is a pattern that helps preventing cascading failures in a system. The circuit breaker pattern allows you to build a fault-tolerant and resilient system that can survive gracefully when key services are either unavailable or have high latency.
It is implemented as a stateful software component that switches between three states:
- closed - requests can flow freely
- open - requests are rejected without being submitted to the remote resource
- half-open - one probe request is allowed to decide whether to close the circuit again
You can provide your own custom global CircuitBreakerConfig. In order to
create a custom global CircuitBreakerConfig, you can use the
CircuitBreakerConfig.builder() method. Using the builder, you can configure
the following properties.
| Parameter | Default value | Description |
|---|---|---|
type |
circuitBreaker |
The type is always circuitBreaker |
automaticTransitionFromOpen
|
false |
If set to true it means that the CircuitBreaker automatically
transitions from open to half-open state and no call is needed to trigger the
transition. A thread is created to monitor all the instances of CircuitBreakers to
transition them to HALF_OPEN once waitDurationInOpenState passes.
Whereas, if set to false the transition to HALF_OPEN only happens if a call is made,
even after waitDurationInOpenState is passed. The advantage here is no thread monitors
the state of all CircuitBreakers. |
failureRateThreshold |
50% | Configures the failure rate threshold in percentage. When the failure rate is equal or greater than the threshold the CircuitBreaker transitions to open and starts short-circuiting calls. |
minimumNumberOfCalls |
100 | Configures the minimum number of calls which are required (per sliding window period) before the CircuitBreaker can calculate the error rate or slow call rate. For example, if minimumNumberOfCalls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been recorded the CircuitBreaker does not transition to open even if all 9 calls have failed. |
name |
GW_CIRCUITBREAKER |
The circuitBreaker name. It is used to create or retrieve the
circuit breaker instance. |
permittedNumberOfCalls
|
10 | Configures the number of permitted calls when the CircuitBreaker is in
HALF_OPEN state. |
slidingWindowType |
COUNT_BASED |
If the sliding window is COUNT_BASED, the last slidingWindowSize
calls are recorded and aggregated. If the sliding window is TIME_BASED, the calls of
the last slidingWindowSize seconds recorded and aggregated.To
determine the count type, default is COUNT_BASED, alternative is
TIME_BASED |
slowCallDurationThreshold |
60000 ms | Configures the duration threshold above which calls are considered as slow and increase the rate of slow calls. |
slowCallRateThreshold |
50 | Configures a threshold in percentage. The CircuitBreaker considers a call as slow
when the call duration is greater than slowCallDurationThreshold.
When the percentage of slow calls is equal or greater the threshold, the
CircuitBreaker transitions to open and starts short-circuiting
calls. |
writableStackTraceEnabled |
true |
Enables writing the stack trace. |
waitIntervalFunctionIn
|
A functional supplier class. When passed a map, it returns an object that
implements IntervalFunction. |
|
recordExceptionSupplierClass |
A functional supplier class. When passed a map, it returns an object that
implements Predicate<Throwable>. |
|
properties |
The map that is passed to the above supplier. The presentation in JSON looks like
"properties":{ "key1":"value", "key2":"value"}). |
See also:
