我想在一个Datastream中加入两个kafka主题。
实际上,两个数据流必须具有相同的ID才能进行连接。 事件是来自传感器的数据,规则包含将使用CEP(来自用户界面)检查的规则。
这是我的测试,但它不起作用,有人可以帮助我吗?
DataStream<Object> evtAndRule=inputEventStream.join(rulesStream)
.where(new KeySelector<TrackEvent, Object>() {
@Override
public Object getKey(Event event) throws Exception {
return event.getId();
}
}).equalTo(new KeySelector<RulesEvent, Object>() {
@Override
public Object getKey(RulesEvent rulesEvent) throws Exception {
return rulesEvent.getId();
}
}).window(TumblingTimeWindows.of(Time.of(10, TimeUnit.SECONDS)))
.apply(new FlatJoinFunction<TrackEvent, RulesEvent, Object>() {
@Override
public void join(TrackEvent trackEvent, RulesEvent rulesEvent, Collector<Object> collector) throws Exception {
....
}
});
答案 0 :(得分:0)
我尝试了这个,但我不知道如何检索所需的规则,如果这是最好的解决方案
DataStream<Tuple2<Event , RulesEvent>> evtAndRule= inputEventStream.map(new MapFunction<Event , Tuple2<Event , RulesEvent>>() {
@Override
public Tuple2<Event , RulesEvent> map(final Event event) throws Exception {
return new Tuple2<Event , RulesEvent>(event, new RulesEvent());
}
});