What is the most efficient way to delete/expire all messages in a Apache Pulsar topic?

4.3k views Asked by At

I'm trying to figure out what would be the best way to remove all the messages from a Pulsar topic (either logically or physically), so that they are no longer consumable by subscriptions?

I know we can simply do $ pulsar-admin persistent delete persistent://tenant/namespace/topic.

But, this solution has some drawbacks: it removes the topic completely (so we have to recreate it later) then there should be no active client connected to it (i.e: subscriptions or producers).

Alternatively is there a way to programmatically make all messages between two MessageId unavailable to the subscriptions ?

Thanks

2

There are 2 answers

0
Sijie Guo On BEST ANSWER

There are a couple of options you can choose from.

0
Yanwt On

From Sijie Guo's answer, I tried skip-all, but got:

Expected a command, got skip-all Invalid command, please use pulsar-admin --help to check out how to use

I retried with clear-backlog with success.

https://github.com/apache/pulsar/issues/5685#issuecomment-664751216
The doc is updated here: https://pulsar.apache.org/docs/pulsar-admin/#list-5
but not here: https://pulsar.apache.org/docs/admin-api-topics#skip-all-messages
So it's confusing