我需要按以下方式处理消息:
streamIn -> process1 -> process2 -> .... -> processN
\ | /
\ | /
sink to kafka
我尝试使用OutputTag
OutputTag<SysmonPartial> filtersOutput = new OutputTag<SysmonPartial>("FiltersOutput"){};
DataStream<SysmonPartial> kafkaSource = env.addSource(consumer);
DataStream<SysmonPartial> source = kafkaSource.rebalance();
SingleOutputStreamOperator<SysmonPartial> s = source
.process(lambda1).name("lambda1").startNewChain()
.process(lambda2).name("lambda2").startNewChain()
.process(lambda3).startNewChain()
.process(lambda4).startNewChain()
.process(lambda5).startNewChain()
.process(lambda6).startNewChain()
.process(lambda7).startNewChain();
SingleOutputStreamOperator<Any> output = s
.getSideOutput(filtersOutput)
.process(filterProcessFunction).setParallelism(1).startNewChain();
output.addSink(sink).setParallelism(1);
env.execute(jobName);
其中lambda 1、2等是条件检查功能,例如
public class Bypass_WS_01_03 extends FilterTagFuction<SysmonPartial, SysmonPartial, SysmonPartial> {
private static final Pattern p_1 = Pattern.compile("pattern1");
private static final Pattern p_0 = Pattern.compile("pattern2");
@Override
public void processElement(SysmonPartial t, Context ctx, Collector<SysmonPartial> out) throws Exception {
out.collect(t);
if (
"1".equals(t.B_VendorEventID) &&
t.CommandLine != null && t.CommandLine.length() != 0 && p_0.matcher(t.CommandLine).find() &&
t.ImageName != null && t.ImageName.length() != 0 && p_1.matcher(t.ImageName).find()
) {
t.RuleId = "Bypass_WS_01_03";
ctx.output(getOutputTag(), t);
}
}
}
但是由于某种原因,它对我不起作用,也许还有其他方法? 据我从文档(https://ci.apache.org/projects/flink/flink-docs-stable/dev/stream/side_output.html)所了解,OutputTag用于创建带有Tag标记的其他消息。还是我错了?
答案 0 :(得分:0)
连接工作图的方式意味着在工作结束时可以访问侧面输出
SingleOutputStreamOperator<Any> output = s
.getSideOutput(filtersOutput)
您只会得到侧面输出中最后一个处理函数,也就是lambda7发出的事件。
我相信您打算做的事情可以表达为
SingleOutputStreamOperator<...> s1 = source.process(lambda1).name("lambda1");
SingleOutputStreamOperator<...> s2 = s1.process(lambda2).name("lambda2");
SingleOutputStreamOperator<...> s3 = s2.process(lambda3);
...
DataStream<...> side1 = s1.getSideOutput(filtersOutput);
DataStream<...> side2 = s2.getSideOutput(filtersOutput);
DataStream<...> side3 = s3.getSideOutput(filtersOutput);
...
SingleOutputStreamOperator<Any> output = side1.union(side2, side3, ...)
.process(filterProcessFunction)
...
此外,我认为您不应该使用startNewChain()
(它会禁用运算符链接)。操作员链接是一种有价值的优化,只有在特殊情况下才应禁用。