简体   繁体   English

kafka 自定义分区器和重新分区

[英]kafka custom partitioner and repartitioning

We can specify custom partitioner for kafka topics.我们可以为 kafka 主题指定自定义分区器。 So the kafka producer can deterministically send message to a particular partition based on certain custom algorithm.因此 kafka 生产者可以根据某些自定义算法确定性地将消息发送到特定分区。

Now the question is, when I increase the number of partitions then How will kafka redistribute the existing messages among new partitions ?现在的问题是,当我增加分区数时,kafka 将如何在新分区之间重新分配现有消息? Or Kafka will not distribute the messages to new partitions ?或者 Kafka 不会将消息分发到新分区? Is it possible to trigger this redistribution ?是否有可能触发这种重新分配? If so, then How will kafka come to know about the custom partitioner as that piece of code resides in the producer part ?如果是这样,那么当那段代码驻留在生产者部分时,kafka 将如何知道自定义分区器?

when I increase the number of partitions then How will kafka redistribute the existing messages among new partitions?当我增加分区数时,kafka 将如何在新分区之间重新分配现有消息?

It will not redistribute the existing messages.它不会重新分发现有的消息。

Is it possible to trigger this redistribution?是否有可能触发这种重新分配?

I am not aware of anything that makes this possible.我不知道有什么能让这成为可能。 Keep in mind, that placing messages into particular partitions will ensure the ordering of those messages within a partition.请记住,将消息放入特定分区将确保这些消息在分区内的排序。 As this could be a quite essential requirement for your appliication it would be very dangerous to shuffle around messages from existing partitions.由于这可能是您的应用程序的一个非常重要的要求,因此从现有分区中随机播放消息将是非常危险的。

If so, then How will kafka come to know about the custom partitioner as that piece of code resides in the producer part?如果是这样,那么当那段代码驻留在生产者部分时,kafka 将如何知道自定义分区器?

Exactly, Kafka does not even have the knowledge how to balance the existing messages accross old and new partitions.确切地说,Kafka 甚至不知道如何平衡旧分区和新分区之间的现有消息。 It could only be done on a random basis which would be quite dangerous for ordering of the messages (see answer to second question).它只能在随机的基础上完成,这对于消息的排序是非常危险的(参见第二个问题的答案)。


We can specify custom partitioner for kafka topics.我们可以为 kafka 主题指定自定义分区器。

Just wanted to emphasize that a custom partitioner is always used at a producer level and you cannot specify a partitioner for a topic .只是想强调,自定义分区器始终用于生产者级别,您不能为主题指定分区器 Imagine the valid scenario where you have multiple producers writing to the same topic.想象一下您有多个生产者写入同一主题的有效场景。 Each producer could have an individual partitioning logic.每个生产者可以有一个单独的分区逻辑。

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

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