Search code examples
azuremessage-queueazureservicebusauto-delete

Azure Service Bus - Auto-delete on idle use cases


According to Microsoft Docs:

Auto-delete on idle enables you to specify an idle interval after which a queue or topic subscription is automatically deleted. The interval is reset when there is traffic on the entity. The minimum duration is 5 minutes.

I also understand, that this is not the same as Message Time to Live, because the whole queue or topic subscription is deleted, not a single message.

Question: What are some real life examples and use cases where Auto-delete on idle is useful?


Solution

  • In Temporary Messaging (in general)

    When you need to set up temporary queues or topics for short-lived communication scenarios, such as request-response patterns or ephemeral messaging needs, you can use auto delete on idle to automatically clean up the resources when they are no longer in use. This helps to avoid accumulating unused messaging entities and reduces management overhead, as well as it helps with cost management.

    In Automated Testing

    If your project is using Automated Tests, which are scheduled every week or every release, you can create a queue programmatically which will be used for tests. In such case, you can enable Auto-delete on idle feature, so the testing queue will be deleted after all tests will end and all test data will be erased.

    In Scheduled Tasks

    Azure Function App timer trigger allows you to run specific function on schedule. For example, you have Function App which reads analytic data from database at the end of every month. Then, it sends all records to Service Bus topic, from where data is picked up by many external services. Since Function App needs to be run only once a month, keeping topics and subscriptions for it all the time is not necessary - you can enable Auto-delete on idle feature, to keep your Service Bus resources clean.

    In Dynamic Scaling

    In scenarios where you dynamically scale your application or services based on workload, auto-delete on idle can be useful. When additional instances of your application or service are spun up to handle increased load, they can create temporary queues/topics for processing messages. If those instances are no longer needed and become idle, auto-delete on idle can ensure that the associated messaging entities are automatically removed, preventing unnecessary resource consumption.