创建 topic
[root@localhost kafka_2.12-2.2.1]# bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic heilu --partitions 2 --replication-factor 1 // 创建 topic 命令
Created topic heilu.
查看 topic
[root@localhost kafka_2.12-2.2.1]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic heilu // 查看topic详细信息
Topic:heilu PartitionCount:2 ReplicationFactor:1 Configs:
Topic: heilu Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: heilu Partition: 1 Leader: 0 Replicas: 0 Isr: 0
修改 topic
[root@localhost kafka_2.12-2.2.1]# bin/kafka-topics.sh --alter --zookeeper 192.168.131.130:2181 --topic heilu --config flush.messages=1
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 heilu.
删除 topic
若 delete.topic.enable=true,直接彻底删除topic。
若 delete.topic.enable=false,如果当前topic没有使用过即没有传输过信息,可以彻底删除。
如果当前topic有使用过即有传输过信息,并没有真正删除topic,只是标记为删除(marked for deletion),重启kafka server 后删除。
[root@localhost kafka_2.12-2.2.1]# bin/kafka-topics.sh --delete --zookeeper 192.168.131.130:2181 --topic heilu // 删除命令
Topic heilu is marked for deletion. // 结果是 标记为删除
Note: This will have no impact if delete.topic.enable is not set to true.
[root@localhost kafka_2.12-2.2.1]#
添加 partitions
只能添加,不能减少
[root@localhost kafka_2.12-2.2.1]# bin/kafka-topics.sh --alter --zookeeper 192.168.131.130:2181 --topic heilu --partitions 3
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!
查看所有topic
[root@localhost kafka_2.12-2.2.1]# bin/kafka-topics.sh --zookeeper localhost:2181 --list // 查看存在 topic 命令
heilu