Operator doc for flatmap merge (#28488)
This commit is contained in:
parent
f891f17abd
commit
a8086e86e5
3 changed files with 89 additions and 7 deletions
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package jdocs.stream.operators.sourceorflow;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.javadsl.Source;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FlatMapMerge {
|
||||
private static ActorSystem system = null;
|
||||
|
||||
// #flatmap-merge
|
||||
// e.g. could be a query to a database
|
||||
private Source<String, NotUsed> lookupCustomerEvents(String customerId) {
|
||||
return Source.from(Arrays.asList(customerId + "-evt-1", customerId + "-evt-2"));
|
||||
}
|
||||
// #flatmap-merge
|
||||
|
||||
void example() {
|
||||
// #flatmap-merge
|
||||
Source.from(Arrays.asList("customer-1", "customer-2"))
|
||||
.flatMapMerge(10, this::lookupCustomerEvents)
|
||||
.runForeach(System.out::println, system);
|
||||
// prints - events from different customers could interleave
|
||||
// customer-1-evt-1
|
||||
// customer-2-evt-1
|
||||
// customer-1-evt-2
|
||||
// customer-2-evt-2
|
||||
// #flatmap-merge
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue