Annotation Interface CircuitBreaker
@Target({METHOD,TYPE})
@Retention(RUNTIME)
@Documented
@Retryable(stateful=true)
public @interface CircuitBreaker
Annotation for a method invocation that is retryable.
- Since:
- 1.2
- Author:
- Dave Syer, Artem Bilan, Gary Russell
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionSpecify an expression to be evaluated after theSimpleRetryPolicy.canRetry()
returns true - can be used to conditionally suppress the retry.Deprecated.Deprecated.in favor ofretryFor()
.A unique label for the circuit for reporting and state management.int
Exception types that are not retryable.Exception types that are not recoverable; these exceptions are thrown to the caller without calling any recoverer (immediately if also innoRetryFor()
).long
WhenmaxAttempts()
failures are reached within this timeout, the circuit is opened automatically, preventing access to the downstream component.WhenmaxAttempts()
failures are reached within this timeout, the circuit is opened automatically, preventing access to the downstream component.Name of method in this class to use for recover.long
If the circuit is open for longer than this timeout then it resets on the next call to give the downstream component a chance to respond again.If the circuit is open for longer than this timeout then it resets on the next call to give the downstream component a chance to respond again.Exception types that are retryable.boolean
Set totrue
to not wrap last exception to theExhaustedRetryException
when retry is exhausted.Deprecated.in favor ofretryFor()
-
Element Details
-
value
Deprecated.in favor ofretryFor()
Exception types that are retryable. Defaults to empty (and if excludes is also empty all exceptions are retried).- Returns:
- exception types to retry
- Default:
- {}
-
include
Deprecated.in favor ofretryFor()
.Exception types that are retryable. Defaults to empty (and if excludes is also empty all exceptions are retried).- Returns:
- exception types to retry
- Default:
- {}
-
retryFor
Exception types that are retryable. Defaults to empty (and, if noRetryFor is also empty, all exceptions are retried).- Returns:
- exception types to retry
- Since:
- 2.0
- Default:
- {}
-
exclude
Deprecated.in favor ofnoRetryFor()
.Exception types that are not retryable. Defaults to empty (and if includes is also empty all exceptions are retried). If includes is empty but excludes is not, all not excluded exceptions are retried- Returns:
- exception types not to retry
- Default:
- {}
-
noRetryFor
Exception types that are not retryable. Defaults to empty (and, if retryFor is also empty, all exceptions are retried). If retryFor is empty but excludes is not, all other exceptions are retried- Returns:
- exception types not to retry
- Since:
- 2.0
- Default:
- {}
-
notRecoverable
Exception types that are not recoverable; these exceptions are thrown to the caller without calling any recoverer (immediately if also innoRetryFor()
). Defaults to empty.- Returns:
- exception types not to retry
- Since:
- 2.0
- Default:
- {}
-
maxAttempts
- Returns:
- the maximum number of attempts (including the first failure), defaults to 3
- Default:
- 3
-
maxAttemptsExpression
- Returns:
- an expression evaluated to the maximum number of attempts (including the
first failure), defaults to 3 Overrides
maxAttempts()
. Use#{...}
for one-time evaluation during initialization, omit the delimiters for evaluation at runtime. - Since:
- 1.2.3
- Default:
- ""
-
label
A unique label for the circuit for reporting and state management. Defaults to the method signature where the annotation is declared.- Returns:
- the label for the circuit
- Default:
- ""
-
resetTimeout
long resetTimeoutIf the circuit is open for longer than this timeout then it resets on the next call to give the downstream component a chance to respond again.- Returns:
- the timeout before an open circuit is reset in milliseconds, defaults to 20000
- Default:
- 20000L
-
resetTimeoutExpression
String resetTimeoutExpressionIf the circuit is open for longer than this timeout then it resets on the next call to give the downstream component a chance to respond again. OverridesresetTimeout()
. Use#{...}
for one-time evaluation during initialization, omit the delimiters for evaluation at runtime.- Returns:
- the timeout before an open circuit is reset in milliseconds, no default.
- Since:
- 1.2.3
- Default:
- ""
-
openTimeout
long openTimeoutWhenmaxAttempts()
failures are reached within this timeout, the circuit is opened automatically, preventing access to the downstream component.- Returns:
- the timeout before a closed circuit is opened in milliseconds, defaults to 5000
- Default:
- 5000L
-
openTimeoutExpression
String openTimeoutExpressionWhenmaxAttempts()
failures are reached within this timeout, the circuit is opened automatically, preventing access to the downstream component. OverridesopenTimeout()
. Use#{...}
for one-time evaluation during initialization, omit the delimiters for evaluation at runtime.- Returns:
- the timeout before a closed circuit is opened in milliseconds, no default.
- Since:
- 1.2.3
- Default:
- ""
-
exceptionExpression
Specify an expression to be evaluated after theSimpleRetryPolicy.canRetry()
returns true - can be used to conditionally suppress the retry. Only invoked after an exception is thrown. The root object for the evaluation is the lastThrowable
. Other beans in the context can be referenced. For example:"message.contains('you can retry this')"
."@someBean.shouldRetry(#root)"
.- Returns:
- the expression.
- Since:
- 1.2.3
- Default:
- ""
-
throwLastExceptionOnExhausted
boolean throwLastExceptionOnExhaustedSet totrue
to not wrap last exception to theExhaustedRetryException
when retry is exhausted.- Returns:
- the boolean flag to whether wrap the last exception to the
ExhaustedRetryException
- Since:
- 2.0.6
- Default:
- false
-
recover
Name of method in this class to use for recover. Method had to be marked withRecover
annotation.- Returns:
- the name of recover method
- Since:
- 2.0.9
- Default:
- ""
-
noRetryFor()
.