import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.java.tuple.Tuple2; import org.apache.flink.configuration.ConfigConstants; import org.apache.flink.configuration.Configuration; import org.apache.flink.streaming.api.datastream.DataStream; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; public class BasicDataStream { public static void main(String[] args) throws Exception { Configuration config = new Configuration(); config.setBoolean(ConfigConstants.LOCAL_START_WEBSERVER, true); StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(config); // Vorher mit nc 127.0.0.1 -kl 9995 den Eingabe-Stream in der Konsole öffnen // Linux/Mac bringt netcat bereits mit, unter Win ggf. nachinstallieren DataStream amounts = env.socketTextStream("localhost", 9995); int threshold = 30; amounts .map(a -> Integer.parseInt(a)) .map(i -> new Tuple2(i, i * 2)) // i verdoppeln, wird aber im Bsp. nicht weiter genutzt .returns(Types.TUPLE(Types.INT, Types.INT)) .keyBy(0) .countWindowAll(2) // immer paarweise zusammenfassen .reduce((x, y) -> new Tuple2<>(x.f0, x.f0 + y.f0)) // und die Paare aufsummieren .returns(Types.TUPLE(Types.INT, Types.INT)) .print(); env.execute(); System.out.println("Ende von main erreicht."); } }