设为首页 加入收藏

TOP

Flume到Kafka且均分到多个partition
2019-05-07 14:11:17 】 浏览:83
Tags:Flume Kafka 均分 多个 partition
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bocai8058/article/details/82954493
@Author  : Spinach | GHB
@Link    : http://blog.csdn.net/bocai8058

说明情况

Flume向kafka发布数据时,发现kafka接收到的数据总是在一个partition中,而我们希望发布来的数据在所有的partition平均分布。

应该怎么做呢?

解决方法

Flume的官方文档是这么说的:

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.

(Kafka Sink使用FlumeEvent标头中的主题和关键属性将事件发送到Kafka。如果标题中存在主题,则会将事件发送到该特定主题,从而覆盖为Sink配置的主题。如果标头中存在密钥,则Kafka将使用密钥对主题分区之间的数据进行分区。具有相同密钥的事件将发送到同一分区。如果密钥为空,则将事件发送到随机分区。)

从上文中的意思,我们可以看出:kafka-sink是从header里的key参数来确定将数据发到kafka的哪个分区中。如果为null,那么就会随机发布至分区中。

但我测试的结果是flume发布的数据会发布到一个分区中的。所以,我们需要向header中写上随机的key,然后数据才会真正的向kafka分区进行随机发布。

我们的办法是,向flume添加拦截器,官方文档说有一个UUID Interceptor,会为每个event的head添加一个随机唯一的key。其实我们直接用这个即可。

# 在flume添加的配置文件如下:
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type=org.apache.flume.sink.solr.morphline.UUIDInterceptor$Builder
a1.sources.r1.interceptors.i1.headerName=key
a1.sources.r1.interceptors.i1.preserveExisting=false

引用:https://www.cnblogs.com/hark0623/p/4710804.html


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ICC副本>>>>(logback.. 下一篇Flume会不会丢失数据?

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目