@Inherited @Retention(value=RUNTIME) @Documented @InterceptorBinding @Target(value={METHOD,TYPE}) public @interface CircuitBreaker
A circuit breaker aims to prevent further damage by not executing functionality that is doomed to fail. After a failure situation has been detected, circuit breakers prevent methods from being executed and instead throw exceptions immediately. After a certain delay or wait time, the functionality is attempted to be executed again.
A circuit breaker can be in one of the following states:
requestVolumeThreshold
and failureRatio
parameters may be configured in order to specify
the conditions under which the breaker will transition the circuit to open. If the failure conditions are met, the circuit
will be opened.
successThreshold
parameter allows the
configuration of the number of trial executions that must succeed before the circuit can be closed. After the specified
number of successful executions, the circuit will be closed. If a failure occurs before the successThreshold is reached
the circuit will transition to open.
Modifier and Type | Optional Element and Description |
---|---|
long |
delay
The delay after which an open circuit will transitions to half-open state.
|
ChronoUnit |
delayUnit
The unit of the delay after which an open circuit will transitions to half-open state.
|
Class<? extends Throwable>[] |
failOn
Defines the failure criteria.
|
double |
failureRatio
The ratio of failures within the rolling window that will trip the circuit to open.
|
int |
requestVolumeThreshold
The number of consecutive requests in a rolling window.
|
int |
successThreshold
The number of successful executions, before a half-open circuit is closed again.
|
public abstract Class<? extends Throwable>[] failOn
A method call will be considered a failure if it throws an exception and the type of that exception is assignable
to any of the types listed in failOn
.
public abstract long delay
The amount of delay is taken from this delay value and the delayUnit
, and defaults to five seconds. The
value must be greater than or equal to 0
. 0
means no delay.
public abstract ChronoUnit delayUnit
delay()
public abstract int requestVolumeThreshold
The circuit breaker will trip if the number of failures exceed the failureRatio
within the rolling window
of consecutive requests. The value must be greater than or equal to 1
.
public abstract double failureRatio
The circuit breaker will trip if the number of failures exceed the failureRatio
within the rolling window
of consecutive requests. For example, if the requestVolumeThreshold
is 20
and failureRatio
is .50
, ten or more failures in 20 consecutive requests will trigger the circuit to open. The value must
be between 0
and 1
inclusive.
public abstract int successThreshold
A half-open circuit will be closed once successThreshold
executions were made without failures.
If a failure occurs while in half-open state the circuit is immediately opened again. The value must be greater
than or equal to 1
.
Copyright © 2019 Eclipse Foundation. All rights reserved.