Kafka Sink uses the topic and key properties from the FlumeEvent headers to send events to
Kafka. If topic exists in the headers, the event will be sent to that specific topic, overriding the
topic configured for the Sink. If key exists in the headers, the key will used by Kafka to partition
the data between the topic partitions. Events with same key will be sent to the same partition.
If the key is null, events will be sent to random partitions.
sink中关于topic和key有这样的描述,其中topic的使用顺序是event中header中的->conf中配置的topic,这样,应该就可以在拦截器中动态配置event中的topic,从而conf中不用配置topic
key应该是作为partition,用于分发,使用顺序也是event中的key->配置的key,如果key是null,消息就到了同一个partition中
其实以上文档中说的很清楚了,kafka-sink是从header里的key参数来确定将数据发到kafka的哪个分区中。如果为null,那么就会随机发布至分区中。但我测试的结果是flume发布的数据会发布到一个分区中的。
所以,我们需要向header中写上随机的key,然后数据才会真正的向kafka分区进行随机发布。
我们的办法是,向flume添加拦截器,官方文档说有一个UUI

Flume Kafka Sink 的分区策略基于 event header 中的 key,若为 null,则消息默认进入同一分区。要实现数据随机分布到不同分区,需在 header 中设置随机 key,如使用 UUID Interceptor 添加唯一 key。Flume 中 Kafka Sink 发送到分区的规则是 header 的 hashcode 除以 partition 数。此外,还讨论了如何在配置中动态设定 topic。
最低0.47元/天 解锁文章
1053

被折叠的 条评论
为什么被折叠?



