我想在一个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 {
....
}
});
我尝试过,但我不知道如何检索所需的规则,如果这是最好的解决方案
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());
}
});