1

How to delete a Kafka topic whose name has space in it?

For Example, Kafka topic name is "test topic", I'm not able to delete it. I'm getting a message called topic does not exist since it is trying to search for the topic "test".

We tried using double quotes ("") for the topic name and back Slash () before the space. Both are not working. I'm currently getting Leader not available recurring errors in topics, I have to delete all the topics present in Kafka to make stable and restart. I need help. Anybody??

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Divya Nayak
  • 67
  • 1
  • 7

2 Answers2

0

You could try with a regex expression (if you don't have any other test_xxx topic that you want to persist, thou):

./bin/kafka-topics.sh --zookeeper zooHost:2181 --delete --topic 'test*'

For example (this is actually a real test):

 ./bin/kafka-topics.sh --zookeeper localhost:2181 --create 
--topic zzzzz --replication-factor 1 --partitions 1
Created topic zzzzz.
 ./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic 'zzz*'
Topic zzzzz is marked for deletion.

This trick may be succesfull when trying to delete such an strange topic name, so hope it helps.

aran
  • 10,978
  • 5
  • 39
  • 69
0

to match a space at the end of topic name for example,

./bin/kafka-topics.sh --zookeeper $(hostname -f):2181 --describe --topic "topicname\\u0020"

Whitespace and Java link I found useful with regard to unicode: Whitespace Matching Regex - Java