繁体   English   中英

带有Kafka源和数据流运行器的Beam Java SDK 2.10.0:窗口Count.perElement永远不会触发数据

[英]Beam java SDK 2.10.0 with Kafka source and Dataflow runner: windowed Count.perElement never fires data out

我在Google DataFlow上将Beam SDK转换为2.10.0作业时遇到问题

流程很简单:我使用Kafka作为源,然后应用“固定”窗口,然后按键计算元素。 但是看起来数据直到工作被耗尽才永远不会离开计数阶段。 Count.PerElement/Combine.perKey(Count)/Combine.GroupedValues.out0输出集合始终为零。 仅在耗尽Dataflow作业后才发布元素。

这是代码:

public KafkaProcessingJob(BaseOptions options) {

    PCollection<GenericRecord> genericRecordPCollection = Pipeline.create(options)
                     .apply("Read binary Kafka messages", KafkaIO.<String, byte[]>read()
                           .withBootstrapServers(options.getBootstrapServers())
                           .updateConsumerProperties(configureConsumerProperties())
                           .withCreateTime(Duration.standardMinutes(1L))
                           .withTopics(inputTopics)
                           .withReadCommitted()
                           .commitOffsetsInFinalize()
                           .withKeyDeserializer(StringDeserializer.class)
                           .withValueDeserializer(ByteArrayDeserializer.class))

                    .apply("Map binary message to Avro GenericRecord", new DecodeBinaryKafkaMessage());

                    .apply("Apply windowing to records", Window.into(FixedWindows.of(Duration.standardMinutes(5)))
                                       .triggering(Repeatedly.forever(AfterWatermark.pastEndOfWindow()))
                                       .discardingFiredPanes()
                                       .withAllowedLateness(Duration.standardMinutes(5)))

                    .apply("Write aggregated data to BigQuery", MapElements.into(TypeDescriptors.strings()).via(rec -> getKey(rec)))
                            .apply(Count.<String>perElement())
                            .apply(
                                new WriteWindowedToBigQuery<>(
                                    project,
                                    dataset,
                                    table,
                                    configureWindowedTableWrite()));   
}

private Map<String, Object> configureConsumerProperties() {
    Map<String, Object> configUpdates = Maps.newHashMap();
    configUpdates.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    return configUpdates;
}

private static String getKey(GenericRecord record) {
    //extract key
}

看起来流永远不会离开.apply(Count.<String>perElement())

有人可以帮忙吗?

我找到了原因。

它与此处使用的TimestampPolicy( .withCreateTime(Duration.standardMinutes(1L)) )有关。

由于我们的Kafka主题中存在空分区,因此从未使用默认的TimestampPolicy推进主题水印。 我需要实施自定义策略来解决此问题。

暂无
暂无

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

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