Limit number of concurrently running instances of a process definition

You can use a service task of type “External”. And then clear the topic one by one using camunda timer that triggers the delegate(lets call this topicDelegate) which has the code to clear the messages in the topic one by one with some delay.

Instead of a fixed delay you can make sure when a camunda process instance completes it makes some kind of entry in some table that you can check in the “topicDelegate”