Provides circuit breaker functionality for stability when working with "dangerous" operations, e.g. calls to remote systems.
Transitions through three states:
- In Closed state, calls pass through until the
maxFailurescount is reached. This causes the circuit breaker to open. Both exceptions and calls exceedingcallTimeoutare considered failures. - In Open state, calls fail-fast with an exception. After
resetTimeout, circuit breaker transitions to half-open state. - In Half-Open state, the first call will be allowed through, if it succeeds the circuit breaker will reset to closed state. If it fails, the circuit breaker will re-open to open state. All calls beyond the first that execute while the first is running will fail-fast with an exception.
Value parameters
- callTimeout
-
scala.concurrent.duration.FiniteDuration of time after which to consider a call a failure
- executor
-
scala.concurrent.ExecutionContext used for execution of state transition listeners
- maxFailures
-
Maximum number of failures before opening the circuit
- randomFactor
-
after calculation of the exponential back-off an additional random delay based on this factor is added, e.g.
0.2adds up to20%delay. randomFactor should be in range0.0(inclusive) and1.0(inclusive). In order to skip this additional delay pass in0. - resetTimeout
-
scala.concurrent.duration.FiniteDuration of time after which to attempt to close the circuit
- scheduler
-
Reference to Pekko scheduler
Attributes
- Companion
- object
- Source
- CircuitBreaker.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Constructors
Attributes
- Source
- CircuitBreaker.scala
Attributes
- Source
- CircuitBreaker.scala
Attributes
- Source
- CircuitBreaker.scala
Attributes
- Source
- CircuitBreaker.scala
Concrete methods
JavaAPI for onCallBreakerOpen.
JavaAPI for onCallBreakerOpen.
Value parameters
- callback
-
Handler to be invoked on call failed due to open breaker.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
JavaAPI for onCallFailure.
JavaAPI for onCallFailure.
Value parameters
- callback
-
Handler to be invoked on failed call, where passed value is elapsed time in nanoseconds.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
JavaAPI for onCallSuccess
JavaAPI for onCallSuccess
Value parameters
- callback
-
Handler to be invoked on successful call, where passed value is elapsed time in nanoseconds.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
JavaAPI for onCallTimeout.
JavaAPI for onCallTimeout.
Value parameters
- callback
-
Handler to be invoked on call finished with timeout, where passed value is elapsed time in nanoseconds.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
JavaAPI for onClose
JavaAPI for onClose
Value parameters
- callback
-
Handler to be invoked on state change
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
JavaAPI for onHalfOpen
JavaAPI for onHalfOpen
Value parameters
- callback
-
Handler to be invoked on state change
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Java API for onOpen
Java API for onOpen
Value parameters
- callback
-
Handler to be invoked on state change
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Java API for withCircuitBreaker.
Java API for withCircuitBreaker.
Value parameters
- body
-
Call needing protected
Attributes
- Returns
-
scala.concurrent.Future containing the call result or a
scala.concurrent.TimeoutExceptionif the call timed out - Source
- CircuitBreaker.scala
Java API for withCircuitBreaker.
Java API for withCircuitBreaker.
Value parameters
- body
-
Call needing protected
- defineFailureFn
-
function that define what should be consider failure and thus increase failure count
Attributes
- Returns
-
scala.concurrent.Future containing the call result or a
scala.concurrent.TimeoutExceptionif the call timed out - Source
- CircuitBreaker.scala
Java API (8) for withCircuitBreaker.
Java API (8) for withCircuitBreaker.
Value parameters
- body
-
Call needing protected
Attributes
- Returns
-
java.util.concurrent.CompletionStage containing the call result or a
scala.concurrent.TimeoutExceptionif the call timed out - Source
- CircuitBreaker.scala
Java API (8) for withCircuitBreaker.
Java API (8) for withCircuitBreaker.
Value parameters
- body
-
Call needing protected
- defineFailureFn
-
function that define what should be consider failure and thus increase failure count
Attributes
- Returns
-
java.util.concurrent.CompletionStage containing the call result or a
scala.concurrent.TimeoutExceptionif the call timed out - Source
- CircuitBreaker.scala
Java API for withSyncCircuitBreaker. Throws java.util.concurrent.TimeoutException if the call timed out.
Java API for withSyncCircuitBreaker. Throws java.util.concurrent.TimeoutException if the call timed out.
Value parameters
- body
-
Call needing protected
Attributes
- Returns
-
The result of the call
- Source
- CircuitBreaker.scala
Java API for withSyncCircuitBreaker. Throws java.util.concurrent.TimeoutException if the call timed out.
Java API for withSyncCircuitBreaker. Throws java.util.concurrent.TimeoutException if the call timed out.
Value parameters
- body
-
Call needing protected
- defineFailureFn
-
function that define what should be consider failure and thus increase failure count
Attributes
- Returns
-
The result of the call
- Source
- CircuitBreaker.scala
Mark a failed call through CircuitBreaker. Sometimes the callee of CircuitBreaker sends back a message to the caller Actor. In such a case, it is convenient to mark a failed call instead of using Future via withCircuitBreaker
Mark a failed call through CircuitBreaker. Sometimes the callee of CircuitBreaker sends back a message to the caller Actor. In such a case, it is convenient to mark a failed call instead of using Future via withCircuitBreaker
Attributes
- Source
- CircuitBreaker.scala
Return true if the internal state is Closed. WARNING: It is a "power API" call which you should use with care. Ordinal use cases of CircuitBreaker expects a remote call to return Future, as in withCircuitBreaker. So, if you check the state by yourself, and make a remote call outside CircuitBreaker, you should manage the state yourself.
Return true if the internal state is Closed. WARNING: It is a "power API" call which you should use with care. Ordinal use cases of CircuitBreaker expects a remote call to return Future, as in withCircuitBreaker. So, if you check the state by yourself, and make a remote call outside CircuitBreaker, you should manage the state yourself.
Attributes
- Source
- CircuitBreaker.scala
Return true if the internal state is HalfOpen. WARNING: It is a "power API" call which you should use with care. Ordinal use cases of CircuitBreaker expects a remote call to return Future, as in withCircuitBreaker. So, if you check the state by yourself, and make a remote call outside CircuitBreaker, you should manage the state yourself.
Return true if the internal state is HalfOpen. WARNING: It is a "power API" call which you should use with care. Ordinal use cases of CircuitBreaker expects a remote call to return Future, as in withCircuitBreaker. So, if you check the state by yourself, and make a remote call outside CircuitBreaker, you should manage the state yourself.
Attributes
- Source
- CircuitBreaker.scala
Return true if the internal state is Open. WARNING: It is a "power API" call which you should use with care. Ordinal use cases of CircuitBreaker expects a remote call to return Future, as in withCircuitBreaker. So, if you check the state by yourself, and make a remote call outside CircuitBreaker, you should manage the state yourself.
Return true if the internal state is Open. WARNING: It is a "power API" call which you should use with care. Ordinal use cases of CircuitBreaker expects a remote call to return Future, as in withCircuitBreaker. So, if you check the state by yourself, and make a remote call outside CircuitBreaker, you should manage the state yourself.
Attributes
- Source
- CircuitBreaker.scala
Adds a callback to execute if call was failed due to open breaker.
Adds a callback to execute if call was failed due to open breaker.
The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on call failed due to open breaker.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Adds a callback to execute if the call finished with failure.
Adds a callback to execute if the call finished with failure.
The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on failed call, where passed value is elapsed time in nanoseconds.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Adds a callback to execute when call finished with success.
Adds a callback to execute when call finished with success.
The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on successful call, where passed value is elapsed time in nanoseconds.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Adds a callback to execute if a call finished with timeout.
Adds a callback to execute if a call finished with timeout.
The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on call finished with timeout, where passed value is elapsed time in nanoseconds.
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Adds a callback to execute when circuit breaker state closes
Adds a callback to execute when circuit breaker state closes
The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on state change
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Adds a callback to execute when circuit breaker transitions to half-open The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Adds a callback to execute when circuit breaker transitions to half-open The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on state change
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Adds a callback to execute when circuit breaker opens
Adds a callback to execute when circuit breaker opens
The callback is run in the scala.concurrent.ExecutionContext supplied in the constructor.
Value parameters
- callback
-
Handler to be invoked on state change
Attributes
- Returns
-
CircuitBreaker for fluent usage
- Source
- CircuitBreaker.scala
Mark a successful call through CircuitBreaker. Sometimes the callee of CircuitBreaker sends back a message to the caller Actor. In such a case, it is convenient to mark a successful call instead of using Future via withCircuitBreaker
Mark a successful call through CircuitBreaker. Sometimes the callee of CircuitBreaker sends back a message to the caller Actor. In such a case, it is convenient to mark a successful call instead of using Future via withCircuitBreaker
Attributes
- Source
- CircuitBreaker.scala
Wraps invocations of asynchronous calls that need to be protected.
Wraps invocations of asynchronous calls that need to be protected.
Value parameters
- body
-
Call needing protected
- defineFailureFn
-
function that define what should be consider failure and thus increase failure count
Attributes
- Returns
-
scala.concurrent.Future containing the call result or a
scala.concurrent.TimeoutExceptionif the call timed out - Source
- CircuitBreaker.scala
Wraps invocations of asynchronous calls that need to be protected.
Wraps invocations of asynchronous calls that need to be protected.
Value parameters
- body
-
Call needing protected
Attributes
- Returns
-
scala.concurrent.Future containing the call result or a
scala.concurrent.TimeoutExceptionif the call timed out - Source
- CircuitBreaker.scala
The resetTimeout will be increased exponentially for each failed attempt to close the circuit. The default exponential backoff factor is 2.
The resetTimeout will be increased exponentially for each failed attempt to close the circuit. The default exponential backoff factor is 2.
Value parameters
- maxResetTimeout
-
the upper bound of resetTimeout
Attributes
- Source
- CircuitBreaker.scala
The resetTimeout will be increased exponentially for each failed attempt to close the circuit. The default exponential backoff factor is 2.
The resetTimeout will be increased exponentially for each failed attempt to close the circuit. The default exponential backoff factor is 2.
Value parameters
- maxResetTimeout
-
the upper bound of resetTimeout
Attributes
- Source
- CircuitBreaker.scala
Adds jitter to the delay.
Adds jitter to the delay.
Value parameters
- randomFactor
-
after calculation of the back-off an additional random delay based on this factor is added, e.g. 0.2 adds up to 20% delay. In order to skip this additional delay pass in 0.
Attributes
- Source
- CircuitBreaker.scala
Wraps invocations of synchronous calls that need to be protected.
Wraps invocations of synchronous calls that need to be protected.
Calls are run in the caller's thread. Because of the synchronous nature of this call, the scala.concurrent.TimeoutException will only be thrown after the body has completed.
Throws java.util.concurrent.TimeoutException if the call timed out.
Value parameters
- body
-
Call needing protected
Attributes
- Returns
-
The result of the call
- Source
- CircuitBreaker.scala
Wraps invocations of synchronous calls that need to be protected.
Wraps invocations of synchronous calls that need to be protected.
Calls are run in caller's thread. Because of the synchronous nature of this call the scala.concurrent.TimeoutException will only be thrown after the body has completed.
Throws java.util.concurrent.TimeoutException if the call timed out.
Value parameters
- body
-
Call needing protected
- defineFailureFn
-
function that define what should be consider failure and thus increase failure count
Attributes
- Returns
-
The result of the call
- Source
- CircuitBreaker.scala
Concrete fields
Attributes
- Source
- CircuitBreaker.scala
Attributes
- Source
- CircuitBreaker.scala
Attributes
- Source
- CircuitBreaker.scala