# Druid 加载 Kafka 流数据配置可以读取和处理的流中数据格式

**URL:** <https://www.isharkfly.com/t/druid-kafka/13666>\
**Category:** BigData\
**Tags:** druid\
**Created:** [August 9, 2021, 5:56pm UTC](https://www.isharkfly.com/t/druid-kafka/13666 "2021-08-09T17:56:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [August 9, 2021, 5:56pm UTC](https://www.isharkfly.com/t/druid-kafka/13666/1 "2021-08-09T17:56:54Z")

</div>

Kafka 索引服务（indexing service）支持 [`inputFormat`](https://druid.ossez.com/#/../../ingestion/data-formats?id=input-format) 和 [`parser`](https://druid.ossez.com/#/../../ingestion/data-formats?id=parser) 来指定特定的数据格式。

`inputFormat` 是一个较新的参数，针对使用的 Kafka 索引服务，我们建议你对这个数据格式参数字段进行设置。 不幸的是，目前还不能支持所有在老的 `parser` 中能够支持的数据格式（Druid 将会在后续的版本中提供支持）。

目前 `inputFormat` 能够支持的数据格式包括有： [`csv`](https://druid.ossez.com/#/../../ingestion/data-formats?id=csv)， [`delimited`](https://druid.ossez.com/#/../../ingestion/data-formats?id=tsv-delimited)， [`json`](https://druid.ossez.com/#/../../ingestion/data-formats?id=json)。

如果你使用 `parser` 的话，你也可以阅读： [`avro_stream`](https://druid.ossez.com/#/../../ingestion/data-formats?id=avro-stream-parser), [`protobuf`](https://druid.ossez.com/#/../../ingestion/data-formats?id=protobuf-parser), [`thrift`](https://druid.ossez.com/#/../extensions-contrib/thrift) 数据格式。

![kafka-data-format-01](https://www.isharkfly.com/images/transparent.png)

因为 Druid 的数据版本的更新，在老的环境下，如果使用 parser 能够处理更多的数格式。

如果通过配置文件来定义的话，在目前只能处理比较少的数据格式。

在我们的系统中，通常将数据格式定义为 JSON 格式，但是因为 JSON 的数据是不压缩的，通常会导致传输数据量增加很多。

![protobuf](https://www.isharkfly.com/images/transparent.png)

如果你想使用 protobuf 的数据格式的话，能够在 Kafka 中传递更多的内容，protobuf 是压缩的数据传输，占用网络带宽更小。

在小型系统中可能不一定会有太大的问题，但是对于大型系统来说，如果传输量小 80% 的话，那占用网络带宽也会小很多，另外也能降低错误率。
