Add docs for circuit breaker new feature #22596
This commit is contained in:
parent
626d07edca
commit
d3de9d40cd
3 changed files with 106 additions and 4 deletions
|
|
@ -0,0 +1,33 @@
|
|||
package docs.circuitbreaker;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.pattern.CircuitBreaker;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class EvenNoFailureJavaExample extends AbstractActor {
|
||||
//#even-no-as-failure
|
||||
private final CircuitBreaker breaker;
|
||||
|
||||
public EvenNoFailureJavaExample() {
|
||||
this.breaker = new CircuitBreaker(
|
||||
getContext().dispatcher(), getContext().system().scheduler(),
|
||||
5, Duration.create(10, "s"), Duration.create(1, "m"));
|
||||
}
|
||||
|
||||
public int luckyNumber() {
|
||||
BiFunction<Optional<Integer>, Optional<Throwable>, Boolean> evenNoAsFailure =
|
||||
(result, err) -> (result.isPresent() && result.get() % 2 == 0);
|
||||
|
||||
// this will return 8888 and increase failure count at the same time
|
||||
return this.breaker.callWithSyncCircuitBreaker(() -> 8888, evenNoAsFailure);
|
||||
}
|
||||
|
||||
//#even-no-as-failure
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue