0

我想在一个数据流中加入两个 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 {
            ....

                }
            });
4

1 回答 1

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());
        }
    });
于 2017-04-24T14:29:15.777 回答