kafka修改删除topic

原创
半兽人 发表于: 2015-03-10   最后更新时间: 2024-02-19 10:28:15  
{{totalSubscript}} 订阅, 25,529 游览

You can change the configuration or partitioning of a topic using the same topic tool.
你可以使用同样的topic工具更改topic的配置和分区。

To add partitions you can do
你可以添加分区

kafka版本 >= 2.2

> bin/kafka-topics.sh --bootstrap-server broker_host:port --alter --topic my_topic_name \
        --partitions 40

kafka版本 < 2.2

> bin/kafka-topics.sh --zookeeper zk_host:port/chroot --create --topic my_topic_name
        --partitions 20 --replication-factor 3 --config x=y

Be aware that one use case for partitions is to semantically partition data, and adding partitions doesn't change the partitioning of existing data so this may disturb consumers if they rely on that partition. That is if data is partitioned byhash(key) % number_of_partitionsthen this partitioning will potentially be shuffled by adding partitions but Kafka will not attempt to automatically redistribute data in any way.
要知道,一个用例的分区是语义上的分区数据,添加分区不能改变现有的数据,如果分区被使用中,这就可能会扰乱消费者。也就是说如果数据通过哈希(key)number_of_partitions划分,那么该分区将通过添加分区进行洗牌,但kafka不以任何方式自动分配数据。

添加配置:

> bin/kafka-configs.sh --bootstrap-server broker_host:port --entity-type topics --entity-name my_topic_name --alter --add-config x=y

移除配置:

> bin/kafka-configs.sh --bootstrap-server broker_host:port --entity-type topics --entity-name my_topic_name --alter --delete-config x

最后删除主题:

> bin/kafka-topics.sh --bootstrap-server broker_host:port --delete --topic my_topic_name

Topic deletion option is disabled by default. To enable it set the server config
topic删除选项默认是关闭的,设置服务器配置开启它。

delete.topic.enable=true

Kafka does not currently support reducing the number of partitions for a topic or changing the replication factor.
kafka目前不支持减少分区数和改变备份数,但是可以通过迁移脚本来实现。

更新于 2024-02-19

Nekonata 5年前

设置了delete.topic.enable=true
show list 看没有了
但是控制台还是出现
Topic foo is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
有大佬知道怎么回事儿吗?

半兽人 -> Nekonata 5年前

标记该主题为delete了。

+ 6年前

kafka的topic是存在哪的,单机版的kafka重新装了一遍,原来的topic还在,并没有随之删除

把你设置的zookeeper的数据存储目录删除就没了

如何充值topic,意思就是回到最初始的状态?

还没重置过。回头我看看。

匿名 6年前

没看明白怎么修改topic的

查看kafka更多相关的文章或提一个关于kafka的问题,也可以与我们一起分享文章