6

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.

David Tinker
  • 557
  • 1
  • 8
  • 16

2 Answers2

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.

Jia Zhai
  • 131
  • 2
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.

MrR
  • 131
  • 1