Flink 侧路输出

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();

执行图如下
Flink 侧路输出_第1张图片

  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();

执行图如下
Flink 侧路输出_第2张图片

你可能感兴趣的:(大数据)