fix circuitbreaker.md

This commit is contained in:
Patrik Nordwall 2017-05-11 16:06:06 +02:00
parent 59f53e1a22
commit 47682ecc72
3 changed files with 42 additions and 56 deletions

View file

@ -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)
@@@ @@@

View file

@ -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* - Exceptions or calls exceeding the configured *callTimeout* increment a failure counter
state: - 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
* Successes reset the failure count to zero * While in *Open* state:
* When the failure counter reaches a *maxFailures* count, the breaker is tripped into *Open* state
- All calls fail-fast with a `CircuitBreakerOpenException`
* - After the configured *resetTimeout*, the circuit breaker enters a *Half-Open* state
While in
*Open* * In *Half-Open* state:
state:
: - The first call attempted is allowed through without failing fast
* All calls fail-fast with a `CircuitBreakerOpenException` - All other calls fail-fast with an exception just as in *Open* state
* After the configured *resetTimeout*, the circuit breaker enters a *Half-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)
*
In * State transition listeners:
*Half-Open*
state: - Callbacks can be provided for every state entry via *onOpen*, *onClose*, and *onHalfOpen*
: - These are executed in the `ExecutionContext` provided.
* The first call attempted is allowed through without failing fast
* All other calls fail-fast with an exception just as in *Open* state * Calls result listeners:
* 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) - 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.
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.
![circuit-breaker-states.png](../images/circuit-breaker-states.png) ![circuit-breaker-states.png](../../images/circuit-breaker-states.png)
## 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`

View file

@ -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)