简体   繁体   English

Kafka Avro 控制台消费者/生产者从文件到文件

[英]Kafka Avro Console Consumer/Producer from and to a File

Is it possible to save Avro encoded messages to a file using Avro Console Consumer and reading from this file to write to another topic using Avro Console Producer given I have a schema string available to provide to the console consumer and producer?是否可以使用 Avro Console Consumer 将 Avro 编码的消息保存到一个文件中,并从这个文件中读取以使用 Avro Console Producer 写入另一个主题,因为我有一个可提供给控制台使用者和生产者的模式字符串? Is this a use cases that are supported out of box or do I need to write a shell script for it?这是一个开箱即用的用例还是我需要为它编写一个shell脚本?

The Avro console producer only accepts JSON encoded strings, not Avro files. Avro 控制台生产者只接受 JSON 编码的字符串,而不接受 Avro 文件。 However, given an Avro file, you can dump its records as JSON and AVSC schema, then it's possible to parse into the console producer (however, it doesn't work in all cases, in my experience).但是,给定一个 Avro 文件,您可以将其记录转储为 JSON 和 AVSC 模式,然后可以解析到控制台生产者(但是,根据我的经验,它并不适用于所有情况)。

You can use Kafka Connect S3 or HDFS sinks (or Apache Nifi) to consume Schema Registry encoded data and write into local Avro files.您可以使用 Kafka Connect S3 或 HDFS sinks(或 Apache Nifi)来使用 Schema Registry 编码的数据并写入本地 Avro 文件。

You can MinIO or Hadoop Ozone to emulate a local S3 endpoint, or you can use the file:// URI prefix with the HDFS connector to write to local disk您可以使用 MinIO 或 Hadoop Ozone 来模拟本地 S3 端点,也可以使用file:// URI 前缀和 HDFS 连接器写入本地磁盘

There's no HDFS source Kafka connector that I know of, but Confluent does provide an S3 source connector.我知道没有 HDFS 源 Kafka 连接器,但 Confluent 确实提供了 S3 源连接器。 Nifi can read and write both file locations, so maybe start with it Nifi 可以读写两个文件位置,所以也许从它开始

Flink or Spark might also work, but have less straightforward Avro serializer settings to make it back into Schema Registry format Flink 或 Spark 也可能工作,但没有那么直接的 Avro 序列化器设置来使其恢复Schema Registry 格式

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

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