简体   繁体   English

基于事件时间的窗口不会触发

[英]Event Time Based Window Doesn't Fire

I am working on Flink event time based window. 我正在基于Flink事件时间的窗口上工作。 But when i send kafka message program does not do windowing operation. 但是当我发送kafka消息程序时不会执行窗口操作。 I did everything what docs say but couldnt solve the problem any help will be appriciated, thanks in advance 我做了文档说的一切,但无法解决问题,需要任何帮助,在此先感谢

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();
        environment.getConfig();
        environment.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
        environment.setParallelism(1);
        Properties props = new Properties();
        props.setProperty("bootstrap.servers", "localhost:9092");
        props.setProperty("group.id","event-group");

        FlinkKafkaConsumer<EventSalesQuantity> consumer = new FlinkKafkaConsumer<EventSalesQuantity>("EventTopic",new EventSerializationSchema(),props);
        DataStream<EventSalesQuantity> eventDataStream = environment.addSource(consumer);

        KeyedStream<EventSalesQuantity, String> keyedEventStream = eventDataStream.assignTimestampsAndWatermarks( new AssignerWithPeriodicWatermarksImpl()).
           keyBy(new KeySelector<EventSalesQuantity, String>() {
               @Override
               public String getKey(EventSalesQuantity eventSalesQuantity) throws Exception {
                   return  eventSalesQuantity.getDealer();
               }
           });

        DataStream<Tuple2<EventSalesQuantity,Integer>> eventSinkStream = keyedEventStream.timeWindow(Time.seconds(5)).aggregate(new AggregateImpl());
        eventSinkStream.addSink(new FlinkKafkaProducer<Tuple2<EventSalesQuantity, Integer>>("localhost:9092","SinkEventTopic",new EventSinkSerializationSchema()));
        eventSinkStream.print();
        environment.execute();
    }
}




public class AssignerWithPeriodicWatermarksImpl implements AssignerWithPeriodicWatermarks<EventSalesQuantity> {
    private final long maxOutOfOrderness = 3500; 
    private long currentMaxTimestamp;

    @Override
    public long extractTimestamp(EventSalesQuantity element, long previousElementTimestamp) {
        long timestamp = DateUtils.getDateFromString(element.getTransactionDate()).getTime();
        currentMaxTimestamp = Math.max(timestamp, currentMaxTimestamp);
        return timestamp;
    }

    @Override
    public Watermark getCurrentWatermark() {
        // return the watermark as current highest timestamp minus the out-of-orderness bound
        return new Watermark(currentMaxTimestamp - maxOutOfOrderness);
    }

"2019-06-21T09:43:01" "2019-06-21T09:43:03" “ 2019-06-21T09:43:01”“ 2019-06-21T09:43:03”

I send 2 messages with these time stamps but i got no output. 我用这些时间戳发送2条消息,但没有输出。

  1. Your event time windows are 5 seconds long. 您的事件时间窗口长5秒。 The window containing those events won't be triggered until it sees a watermark with a timestamp of at least 2019-06-21T09:43:05. 包含这些事件的窗口只有在看到时间戳至少为2019-06-21T09:43:05的水印时才会被触发。
  2. With the maxOutOfOrderness set to 3500 msec, your watermark generator won't generate a watermark large enough to trigger the window until it has seen an event with a timestamp of at least 2019-06-21T09:43:08.500. 将maxOutOfOrderness设置为3500毫秒,您的水印生成器将不会生成足以触发窗口的水印,直到它看到时间戳至少为2019-06-21T09:43:08.500的事件为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM