Restart(Source|Flow|Sink): Configurable stream restart deadline (#29591)

This commit is contained in:
r-glyde 2020-10-05 08:12:15 +01:00 committed by GitHub
parent 4cc3c58a08
commit a4acf23d05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 727 additions and 347 deletions

View file

@ -9,6 +9,7 @@ import akka.actor.ActorSystem;
import akka.stream.KillSwitch;
import akka.stream.KillSwitches;
import akka.stream.Materializer;
import akka.stream.RestartSettings;
import akka.stream.javadsl.Keep;
import akka.stream.javadsl.RestartSource;
import akka.stream.javadsl.Sink;
@ -61,12 +62,18 @@ public class RestartDocTest {
public void recoverWithBackoffSource() {
// #restart-with-backoff-source
RestartSettings settings =
RestartSettings.create(
Duration.ofSeconds(3), // min backoff
Duration.ofSeconds(30), // max backoff
0.2 // adds 20% "noise" to vary the intervals slightly
)
.withMaxRestarts(
20, Duration.ofMinutes(5)); // limits the amount of restarts to 20 within 5 minutes
Source<ServerSentEvent, NotUsed> eventStream =
RestartSource.withBackoff(
Duration.ofSeconds(3), // min backoff
Duration.ofSeconds(30), // max backoff
0.2, // adds 20% "noise" to vary the intervals slightly
20, // limits the amount of restarts to 20
settings,
() ->
// Create a source from a future of a source
Source.completionStageSource(