Kafka的主题操作命令

Kafka的主题操作命令

因为总是经常忘记,所以汇总一下。

前提

卡夫卡版本:0.11
Zookeeper运行位置:本地主机:2181

我们将命令执行位置设置为Kafka的部署目录。

命令组

创建主题

(Chuangjian zhuti)

./bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 1 --topic sample1
Created topic "sample1".

复制因子: 简单来说,是消息的副本数量。
分区数: 主题内的分区数量。

阅读有关Kafka配置和主题的文档是关于参数的一个良好选择。

展示tpic的列表

./bin/kafka-topics.sh --zookeeper localhost:2181 --list
sample1

主题:详细确认

./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic sample1
Topic:sample1   PartitionCount:1    ReplicationFactor:1 Configs:
    Topic: sample1  Partition: 0    Leader: 1   Replicas: 1 Isr: 1

修正主题。

./bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic sample1 --config max.message.bytes=128000
WARNING: Altering topic configuration from this script has been deprecated and may be removed in future releases.
         Going forward, please use kafka-configs.sh for this functionality
Updated config for topic "sample1".

虽然有警告,但似乎能够成功执行。由于配置文件有很多参数,请务必阅读文档。

主题删除

./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic sample1
Note: This will have no impact if delete.topic.enable is not set to true.

如果在Kafka启动参数中没有指定delete.topic.enable=true(默认为config/server.properties),则无法删除。