Provide an API for purging of a queue, without having to delete and recreate the queue.
James Spielvogel commented
Just use PeekBatch to read all the messages in the queue sequentially (even locked ones, because this method does not lock from what I understand), back them up (system properties + user properties + payload stream == complete representation of message), and then recreate the queue with same name, settings, and credentials. It only takes a couple seconds to do. If the process is disrupted at all, just resume at 1+ the last sequence number you backed up, since PeekBatch supports starting at a specific sequence number. I'm not entirely sure what the behavior is with partitioned queues, since it might return the lowest sequence number for whatever partition returns first, but it may still enumerate all messages in all partitions. Also, when using PeekBatch and specifying a batch size, set the QueueClient's BatchSize to the same batch size you pass to PeekBatch.
This is interesting, but still very unclear: https://docs.microsoft.com/en-us/answers/questions/137685/how-peek-works-in-a-partition-enabled-service-bus.html It sounds like... if there are 16 partitions, PeekBatch will begin reading from whichever responds first. So for example, if partition 5 responds first, repeated calls to PeekBatch will enumerate through that partition first. Presumably, it keeps track of which partitions it has already visited, and once finished with one of them, it will pick up enumeration on another available partition, and so on, until it has completely enumerated all messages in all partitions.
Saravana Kumar commented
ServiceBus360 (https://www.servicebus360.com/) supports it, there is also a free account with 3 namespaces to get started.
Dr. Thomas Berisford commented
It would be exponentially more useful if there was a flag to purge, even if a message was locked (Obviously for development reasons) I often find myself waiting for a lock to clear on the development queues.
Sean Feldman commented
Also testing scenarios, where between test runs queues need to be purged.
Stuart Blackler commented
This could be extremely handy for development scenarios.