DataStream<String> text = env.socketTextStream(hostname, port, "\n");
text.filter(e->Integer.parseInt(e)>20).print();
text.filter(e->Integer.parseInt(e)>10).print();
env.execute();
执行图如下
DataStream<String> text = env.socketTextStream(hostname, port, "\n");
OutputTag<String> sideOutputTag = new OutputTag<String>("side-output-tag"){};
SingleOutputStreamOperator<Object> process = text.process(new ProcessFunction<String, Object>() {
@Override
public void processElement(String s, Context context, Collector<Object> collector) throws Exception {
if (Integer.parseInt(s) > 20) {
context.output(sideOutputTag, s);
}
if (Integer.parseInt(s) > 10) {
collector.collect(s);
}
}
});
process.getSideOutput(sideOutputTag).print();
process.print();
执行图如下