首页 > 解决方案 > 如何在 Apache Beam 中实现类似于 Spark 的累加器的变量

问题描述

我目前在 Spark 中使用 Apache Beam 2.29.0。我的管道使用来自 Kafka 的数据,为此我有一个自定义的 KafkaConsumer,Beam 通过调用 ConsumerFactoryFn 来创建该数据。在运行期间,我需要在自定义 Kafka 消费者之间共享一段持久数据。这在 Spark 中非常简单,我将创建一个 Accumulator 变量,所有执行程序以及驱动程序都可以访问该变量。由于 Beam 旨在在多个平台上运行 Spark、Flink、Google Dataflow,因此它不提供此功能。有人知道实现这一点的方法吗?

标签: apache-beam

解决方案


I believe Side Inputs should work. You can read about the Side Inputs here. A side input is an additional input that your DoFn can access each time it processes an element in the input PCollection.

Here Is an example of how to use it.


推荐阅读