使用 Flink 动态消费和下沉 Kafka 主题
Dynamically consume and sink Kafka topics with Flink
我无法在网上找到很多关于此的信息。我想知道是否有可能构建一个 Flink 应用程序,该应用程序可以动态使用与正则表达式模式匹配的所有主题并将这些主题同步到 s3。此外,每个动态同步的主题都会有 Avro 消息,Flink 应用程序会使用 Confluent 的 Schema Registry。
Flink 1.4 中添加了使用正则表达式模式订阅 Kafka 主题。见 documentation here.
S3是Flink支持的文件系统之一。要将流可靠地一次性传送到文件系统,请使用 flink-connector-filesystem connector.
您可以将 Flink 配置为使用 Avro,但我不确定与 Confluent 的模式注册表互操作的状态如何。
要搜索这些和其他主题,我建议在 Flink 文档页面上进行搜索。例如:https://ci.apache.org/projects/flink/flink-docs-release-1.4/search-results.html?q=schema+registry
真幸运! Flink 1.4 刚刚发布几天,这是第一个使用 REGEX 提供消费 Kafka 主题的版本。根据 java 文档,这里是您如何使用它:
FlinkKafkaConsumer011
public FlinkKafkaConsumer011(PatternsubscriptionPattern,DeserializationSchema<T> valueDeserializer,Properties props)
Creates a new Kafka streaming source consumer for Kafka 0.11.x. Use
this constructor to subscribe to multiple topics based on a regular
expression pattern. If partition discovery is enabled (by setting a
non-negative value for
FlinkKafkaConsumerBase.KEY_PARTITION_DISCOVERY_INTERVAL_MILLIS in the
properties), topics with names matching the pattern will also be
subscribed to as they are created on the fly.
Parameters:
subscriptionPattern - The regular expression for a pattern of topic names to subscribe to.
valueDeserializer - The de-/serializer used to convert between Kafka's byte messages and Flink's objects.
props - The properties used to configure the Kafka consumer client, and the ZooKeeper client.
只需注意 运行 Flink 流式应用程序,它会以使用消费者配置指定的时间间隔从 Zookeeper 获取主题数据:
FlinkKafkaConsumerBase.KEY_PARTITION_DISCOVERY_INTERVAL_MILLIS
这意味着每个消费者都应该重新同步包括主题在内的元数据,在某些指定的 intervals.The 默认值是 5 分钟。所以添加一个新主题你应该期望消费者最多在 5 分钟内开始消费它。您应该使用所需的时间间隔为 Flink 消费者设置此配置。
我无法在网上找到很多关于此的信息。我想知道是否有可能构建一个 Flink 应用程序,该应用程序可以动态使用与正则表达式模式匹配的所有主题并将这些主题同步到 s3。此外,每个动态同步的主题都会有 Avro 消息,Flink 应用程序会使用 Confluent 的 Schema Registry。
Flink 1.4 中添加了使用正则表达式模式订阅 Kafka 主题。见 documentation here.
S3是Flink支持的文件系统之一。要将流可靠地一次性传送到文件系统,请使用 flink-connector-filesystem connector.
您可以将 Flink 配置为使用 Avro,但我不确定与 Confluent 的模式注册表互操作的状态如何。
要搜索这些和其他主题,我建议在 Flink 文档页面上进行搜索。例如:https://ci.apache.org/projects/flink/flink-docs-release-1.4/search-results.html?q=schema+registry
真幸运! Flink 1.4 刚刚发布几天,这是第一个使用 REGEX 提供消费 Kafka 主题的版本。根据 java 文档,这里是您如何使用它:
FlinkKafkaConsumer011
public FlinkKafkaConsumer011(PatternsubscriptionPattern,DeserializationSchema<T> valueDeserializer,Properties props)
Creates a new Kafka streaming source consumer for Kafka 0.11.x. Use this constructor to subscribe to multiple topics based on a regular expression pattern. If partition discovery is enabled (by setting a non-negative value for FlinkKafkaConsumerBase.KEY_PARTITION_DISCOVERY_INTERVAL_MILLIS in the properties), topics with names matching the pattern will also be subscribed to as they are created on the fly.
Parameters:
subscriptionPattern - The regular expression for a pattern of topic names to subscribe to. valueDeserializer - The de-/serializer used to convert between Kafka's byte messages and Flink's objects.
props - The properties used to configure the Kafka consumer client, and the ZooKeeper client.
只需注意 运行 Flink 流式应用程序,它会以使用消费者配置指定的时间间隔从 Zookeeper 获取主题数据:
FlinkKafkaConsumerBase.KEY_PARTITION_DISCOVERY_INTERVAL_MILLIS
这意味着每个消费者都应该重新同步包括主题在内的元数据,在某些指定的 intervals.The 默认值是 5 分钟。所以添加一个新主题你应该期望消费者最多在 5 分钟内开始消费它。您应该使用所需的时间间隔为 Flink 消费者设置此配置。