I'm learning about Java Akka streams and using https://doc.akka.io/docs/akka/current/stream/stream-flows-and-basics.html have defined the following:
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
public class SourceExample {
static ActorSystem system = ActorSystem.create("SourceExample");
public static void main(String args[]) throws ExecutionException, InterruptedException {
final List<Integer> sourceData = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
final Source<Integer, NotUsed> source =
Source.from(sourceData);
final Sink<Integer, CompletionStage<Integer>> sink =
Sink.<Integer, Integer>fold(0, (agg, next) -> agg + next);
final CompletionStage<Integer> sum = source.runWith(sink, system);
System.out.println(sum.toCompletableFuture().get());
}
}
Running this code behaves as expected.
Is the problem Akka Streams is resolving that this code can be executed repeatedly.
In a real-world scenario, sourceData
will not be static, does Akka Streams have an opinion as to how changing data should be handled or is it determined by the developer?
In the simplest case just re-execute the streaming Flow every X minutes (using a scheduled Task for example) when the source data changes. Or are Akka streams long-lived, the source data changes and the stream computations are re-executed according to some parameters?
The Akka Streams documentation defines multiple sources of data but I don't understand how Akka Streams should be utilised to handle changing source data.