简体   繁体   English

从Kafka客户端增加Kafka主题中的分区数

[英]Increase number of partitions in a Kafka topic from a Kafka client

I'm a new user of Apache Kafka and I'm still getting to know the internals. 我是Apache Kafka的新用户,我仍然了解内部。

In my use case, I need to increase the number of partitions of a topic dynamically from the Kafka Producer client. 在我的用例中,我需要从Kafka Producer客户端动态增加主题的分区数。

I found other similar questions regarding increasing the partition size, but they utilize the zookeeper configuration. 我发现了有关增加分区大小的其他类似问题 ,但它们使用了zookeeper配置。 But my kafkaProducer has only the Kafka broker config, but not the zookeeper config. 但我的kafkaProducer只有Kafka代理配置,但没有zookeeper配置。

Is there any way I can increase the number of partitions of a topic from the Producer side? 有没有办法可以从Producer端增加主题的分区数量? I'm running Kafka version 0.10.0.0. 我正在运行Kafka版本0.10.0.0。

As of Kafka 0.10.0.1 (latest release): As Manav said it is not possible to increase the number of partitions from the Producer client. 截至Kafka 0.10.0.1(最新版本):正如Manav所说,无法增加Producer客户端的分区数量。

Looking ahead (next releases): In an upcoming version of Kafka, clients will be able to perform some topic management actions, as outlined in KIP-4 . 展望未来(下一版本):在即将推出的Kafka版本中,客户将能够执行一些主题管理操作,如KIP-4中所述 A lot of the KIP-4 functionality is already completed and available in Kafka's trunk ; 许多KIP-4功能已经完成并可在Kafka的trunk ; the code in trunk as of today allows client to create and to delete topics. 今天的trunk的代码允许客户端创建和删除主题。 But unfortunately, for your use case, increasing the number of partitions is still not possible yet -- this is in scope for KIP-4 (see Alter Topics Request ) but is not completed yet. 但遗憾的是,对于您的用例,仍然无法增加分区数量 - 这是KIP-4的范围(请参阅更改主题请求 )但尚未完成。

TL;DR: The next versions of Kafka will allow you to increase the number of partitions of a Kafka topic, but this functionality is not yet available. TL; DR:Kafka的下一个版本将允许您增加Kafka主题的分区数,但此功能尚不可用。

It is not possible to increase the number of partitions from the Producer client. 无法从Producer客户端增加分区数。 Any specific use case use why you cannot use the broker to achieve this ? 任何特定用例都使用为什么你不能使用代理实现这一目的?

But my kafkaProducer has only the Kafka broker config, but not the zookeeper config. 但我的kafkaProducer只有Kafka代理配置,但没有zookeeper配置。

I don't think any client will let you change the broker config. 我认为任何客户端都不允许您更改代理配置。 You can only access (read) the server side config at max. 您最多只能访问(读取)服务器端配置。

Your producer can provide different keys for ProducerRecord's. 您的制作人可以为ProducerRecord提供不同的密钥。 The broker would place them in different partitions. 代理将它们放在不同的分区中。 For example, if you need two partitions, use keys "abc" and "xyz". 例如,如果您需要两个分区,请使用“abc”和“xyz”键。

This can be done in version 0.9 as well. 这也可以在0.9版本中完成。

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

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