我已发出删除主题的命令:

./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic  vip_ips_alerts

它似乎给出了一个愉快的回应:

[2014-05-31 20:58:10,112] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkClient)
Topic "vip_ips_alerts" queued for deletion.

但现在10分钟后这个话题仍然出现在--list命令:

./bin/kafka-topics.sh --zookeeper localhost:2181 --list
vip_ips_alerts - marked for deletion

那么这意味着什么呢?真的删除了?

答案

tl;drdelete.topic.enable = trueconfig/server.properties卡夫卡经纪人和……要有耐心。

最新开发版本的 Kafka 会出现这种情况0.8.3-SNAPSHOT

➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗ ./bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic my-topic --partitions 2 --replication-factor 1
Created topic "my-topic".

➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗ ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic my-topic
Topic:my-topic  PartitionCount:2    ReplicationFactor:1 Configs:
    Topic: my-topic Partition: 0    Leader: 0   Replicas: 0 Isr: 0
    Topic: my-topic Partition: 1    Leader: 0   Replicas: 0 Isr: 0

➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗ ./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic my-topic
Topic my-topic is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗ ./bin/kafka-topics.sh --zookeeper localhost:2181 --list
➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗

重点是要有delete.topic.enable=trueconfig/server.properties用于启动 Kafka 代理。

➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗ grep delete.topic.enable config/server.properties
delete.topic.enable=true

您还可以确保代理日志中的设置为 true:

➜  kafka_2.11-0.8.3-SNAPSHOT git:(trunk) ✗ ./bin/kafka-server-start.sh config/server.properties
[2015-07-24 22:33:26,184] INFO KafkaConfig values:
        ...
        delete.topic.enable = true

来自: stackoverflow.com