如何在Apache Kafka中删除多个主题 [英] How to delete multiple topics in Apache Kafka
问题描述
假设我有多个主题具有相同的前缀,例如:
Assuming that I have a number of topics with the same prefix, e.g:
giorgos-topic1
giorgos-topic2
giorgos-topic3
...
用于删除单个主题(例如 giorgos-topic1
)的命令如下:
The command used for deleting a single topic (say giorgos-topic1
) is the following:
./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic giorgos-topic1
是否可以使用单个命令以及正则表达式/通配符(例如 giorgos-*
)删除多个主题,而不用键入需要一一删除的所有主题名称?
Is it possible to delete multiple topics using a single command and possibly a regular expression/wildcard (e.g. giorgos-*
) instead of typing all the topic names that need to be deleted one by one?
推荐答案
是的,当您使用 kafka-topics.sh
工具删除主题时,可以使用类似正则表达式的表达式:
Yes you can use regex-like expressions when deleting topics with the kafka-topics.sh
tool:
例如,要删除以 giorgos-
开头的所有主题:
For example, to delete all topics starting with giorgos-
:
./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic 'giorgos-.*'
使用Admin API,您还可以一次删除多个主题,请参见 AdminClient.deleteTopics
这篇关于如何在Apache Kafka中删除多个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!