The Akka CircuitBreaker
can be combined with Reactive Streams as follows.
The core of the process is
.mapAsync(6) { x =>
lookup(x) recover {
case e: CircuitBreakerOpenException => "open"
case _@ x => x.toString
}
}
which:
- requests a result from the rejectMoreThanTwo function.
- Replaces the exception generated by open CB with the value “open”.
- Converts an other result to its string representation.
The output is
AA
B
java.lang.IllegalArgumentException: xxxxxxxxxxxxxxxx
open
open
open
The runnable application code