Is there a way to use the Pulsar command line tools to delete all messages for a topic? It doesn't have any subscriptions yet and from what I can tell the tools that do this operate on a subscription. I need to get rid of the old junk before starting the service that consumes the topic.
Asked
Active
Viewed 3,729 times
2 Answers
8
@David Tinker, Please try this delete topic command:
$ pulsar-admin persistent delete persistent://test-tenant/ns1/tp1
Before execute, there should be not any active subscription or producer connected to it. If topic has subscription and producers connected, and you done care the existing data, you could add --force
at the end.
After delete this topic, when produce data, producer will reconnect and auto create the topic with same name.
![](../../users/profiles/507287.webp)
Jia Zhai
- 131
- 2
-
Didn't work. I added "--force" and the topic is still there. No mention of the `--force` flag in the documentation. – lucid_dreamer Apr 21 '21 at 21:19
-
doh! `--force` succeeds but the topic gets recreated if a publisher is active. – lucid_dreamer Apr 22 '21 at 10:53
3
See the documentation.
List the topics with:
pulsar-admin persistent list tenant/namespace
Then to delete them:
pulsar-admin topics delete "persistent://tenant/namespace/topic
or:
pulsar-admin topics delete "persistent://tenant/namespace/topic" --force
You can check subscribers with:
pulsar-admin persistent subscriptions "persistent://tenant/namespace/topic"
You can check publishers with (publisher section of the output):
pulsar-admin topics stats "persistent://tenant/namespace/topic"
If you use the force option, beware any connected publishers might immediately recreate the topic.
![](../../users/profiles/432556.webp)
MrR
- 131
- 1