fix circuitbreaker.md
This commit is contained in:
parent
59f53e1a22
commit
47682ecc72
3 changed files with 42 additions and 56 deletions
|
|
@ -7,8 +7,8 @@
|
||||||
* [event-bus](event-bus.md)
|
* [event-bus](event-bus.md)
|
||||||
* [logging](logging.md)
|
* [logging](logging.md)
|
||||||
* [scheduler](scheduler.md)
|
* [scheduler](scheduler.md)
|
||||||
* [../scala/common/duration](../scala/common/duration.md)
|
* [common/duration](common/duration.md)
|
||||||
* [../scala/common/circuitbreaker](../scala/common/circuitbreaker.md)
|
* [common/circuitbreaker](common/circuitbreaker.md)
|
||||||
* [extending-akka](extending-akka.md)
|
* [extending-akka](extending-akka.md)
|
||||||
|
|
||||||
@@@
|
@@@
|
||||||
|
|
@ -29,60 +29,47 @@ The Akka library provides an implementation of a circuit breaker called
|
||||||
|
|
||||||
## What do they do?
|
## What do they do?
|
||||||
|
|
||||||
*
|
* During normal operation, a circuit breaker is in the *Closed* state:
|
||||||
During normal operation, a circuit breaker is in the
|
|
||||||
*Closed*
|
|
||||||
state:
|
|
||||||
:
|
|
||||||
* Exceptions or calls exceeding the configured *callTimeout* increment a failure counter
|
|
||||||
* Successes reset the failure count to zero
|
|
||||||
* When the failure counter reaches a *maxFailures* count, the breaker is tripped into *Open* state
|
|
||||||
|
|
||||||
*
|
- Exceptions or calls exceeding the configured *callTimeout* increment a failure counter
|
||||||
While in
|
- Successes reset the failure count to zero
|
||||||
*Open*
|
- When the failure counter reaches a *maxFailures* count, the breaker is tripped into *Open* state
|
||||||
state:
|
|
||||||
:
|
|
||||||
* All calls fail-fast with a `CircuitBreakerOpenException`
|
|
||||||
* After the configured *resetTimeout*, the circuit breaker enters a *Half-Open* state
|
|
||||||
|
|
||||||
*
|
* While in *Open* state:
|
||||||
In
|
|
||||||
*Half-Open*
|
|
||||||
state:
|
|
||||||
:
|
|
||||||
* The first call attempted is allowed through without failing fast
|
|
||||||
* All other calls fail-fast with an exception just as in *Open* state
|
|
||||||
* If the first call succeeds, the breaker is reset back to *Closed* state and the *resetTimeout* is reset
|
|
||||||
* If the first call fails, the breaker is tripped again into the *Open* state (as for exponential backoff circuit breaker, the *resetTimeout* is multiplied by the exponential backoff factor)
|
|
||||||
|
|
||||||
*
|
- All calls fail-fast with a `CircuitBreakerOpenException`
|
||||||
State transition listeners:
|
- After the configured *resetTimeout*, the circuit breaker enters a *Half-Open* state
|
||||||
:
|
|
||||||
* Callbacks can be provided for every state entry via *onOpen*, *onClose*, and *onHalfOpen*
|
|
||||||
* These are executed in the `ExecutionContext` provided.
|
|
||||||
|
|
||||||
*
|
* In *Half-Open* state:
|
||||||
Calls result listeners:
|
|
||||||
:
|
- The first call attempted is allowed through without failing fast
|
||||||
* Callbacks can be used eg. to collect statistics about all invocations or to react on specific call results like success, failures or timeouts.
|
- All other calls fail-fast with an exception just as in *Open* state
|
||||||
* Supported callbacks are: *onCallSuccess*, *onCallFailure*, *onCallTimeout*, *onCallBreakerOpen*.
|
- If the first call succeeds, the breaker is reset back to *Closed* state and the *resetTimeout* is reset
|
||||||
* These are executed in the `ExecutionContext` provided.
|
- If the first call fails, the breaker is tripped again into the *Open* state (as for exponential backoff circuit breaker, the *resetTimeout* is multiplied by the exponential backoff factor)
|
||||||
|
|
||||||
|
* State transition listeners:
|
||||||
|
|
||||||
|
- Callbacks can be provided for every state entry via *onOpen*, *onClose*, and *onHalfOpen*
|
||||||
|
- These are executed in the `ExecutionContext` provided.
|
||||||
|
|
||||||
|
* Calls result listeners:
|
||||||
|
|
||||||
|
- Callbacks can be used eg. to collect statistics about all invocations or to react on specific call results like success, failures or timeouts.
|
||||||
|
- Supported callbacks are: *onCallSuccess*, *onCallFailure*, *onCallTimeout*, *onCallBreakerOpen*.
|
||||||
|
- These are executed in the `ExecutionContext` provided.
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### Initialization
|
### Initialization
|
||||||
|
|
||||||
Here's how a :class:
|
Here's how a `CircuitBreaker` would be configured for:
|
||||||
*CircuitBreaker*
|
|
||||||
would be configured for:
|
* 5 maximum failures
|
||||||
:
|
* a call timeout of 10 seconds
|
||||||
* 5 maximum failures
|
* a reset timeout of 1 minute
|
||||||
* a call timeout of 10 seconds
|
|
||||||
* a reset timeout of 1 minute
|
|
||||||
|
|
||||||
|
|
||||||
#### Scala
|
#### Scala
|
||||||
|
|
@ -131,12 +118,11 @@ However, some applications might requires certain exception to not increase fail
|
||||||
sometime we want to increase the failure count even if the call succeeded.
|
sometime we want to increase the failure count even if the call succeeded.
|
||||||
Akka circuit breaker provides a way to achieve such use case:
|
Akka circuit breaker provides a way to achieve such use case:
|
||||||
|
|
||||||
>
|
* `withCircuitBreaker`
|
||||||
* *withCircuitBreaker*
|
* `withSyncCircuitBreaker`
|
||||||
* *withSyncCircuitBreaker*
|
* `callWithCircuitBreaker`
|
||||||
* *callWithCircuitBreaker*
|
* `callWithCircuitBreakerCS`
|
||||||
* *callWithCircuitBreakerCS*
|
* `callWithSyncCircuitBreaker`
|
||||||
* *callWithSyncCircuitBreaker*
|
|
||||||
|
|
||||||
All methods above accepts an argument `defineFailureFn`
|
All methods above accepts an argument `defineFailureFn`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
* [event-bus](event-bus.md)
|
* [event-bus](event-bus.md)
|
||||||
* [logging](logging.md)
|
* [logging](logging.md)
|
||||||
* [scheduler](scheduler.md)
|
* [scheduler](scheduler.md)
|
||||||
* [../scala/common/duration](../scala/common/duration.md)
|
* [common/duration](../scala/common/duration.md)
|
||||||
* [../scala/common/circuitbreaker](../scala/common/circuitbreaker.md)
|
* [../scala/common/circuitbreaker](../scala/common/circuitbreaker.md)
|
||||||
* [extending-akka](extending-akka.md)
|
* [extending-akka](extending-akka.md)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue