9

The scenario I have in mind is this: Service Bus is used for instance-to-instance communication, so a Subscription is unique per service instance. The end result is that if an instance does not shut down gracefully, its subscription does not get deleted.

When a service instance "dies" and restarts, previous contents of the subscription are irrelevant and can be discarded.

So, is there a way to set a "time to live" for Service Bus Subscription or simulate something similar, without having to resort to some custom orphan detection mechanism?

Andrei
  • 1,015
  • 1
  • 11
  • 19

3 Answers3

7

Starting with Azure SDK 2.0 this works as expected.

Also, contrary to other reports, in my testing, subscription does not get deleted as long as there is a pending receiver listening to that subscription.

var description = new SubscriptionDescription(topicPath, subscriptionId);
description.AutoDeleteOnIdle = TimeSpan.FromSeconds(600);
namespaceManager.CreateSubscription(description);
Andrei
  • 1,015
  • 1
  • 11
  • 19
5

that exact feature is on the backlog for one of the next releases. that said, in azure you could use the instance-id fro the role environment to create the name of your subscription and thus have a restarting instance reuse a subscription. the instance-id names are stable.

Edit: The feature is AutoDeleteOnIdle https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.subscriptiondescription

Clemens Vasters
  • 2,666
  • 16
  • 28
  • Thank you for your answer, Clemens. Using Instance ID to create subscription names is exactly what we are doing, but there's still quite a bit of garbage left from all the debug sessions with development fabric instance names being generated using PID numbers. – Andrei Nov 03 '12 at 19:05
  • 1
    @Clemens any idea when this might be released? – Pete Duncanson Feb 20 '13 at 11:59
  • I am also looking for when this might be released. I have a similar usecase for silverlight client subscriptions per client. There might be an option to roll your own cleanup if you know the topic names by looking for stale subscriptions. : http://stackoverflow.com/questions/15871119/cleaning-up-stale-azure-service-bus-topic-subscriptions – kjsteuer Apr 12 '13 at 11:52
1

I had the exact same problem, preview solving it was released beginning of 2013: http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.subscriptiondescription.autodeleteonidle.aspx

It's very easy to use (see example below). Unfortunately it seems that the subscription times out if there is no message published for the AutoDeleteOnIdle period, even if you have some process awaiting for messages (according to Azure Servicebus AutoDeleteOnIdle).

NamespaceManager manager=NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);
if(!manager.SubscriptionExists(topic,subscriptionName))
{
    manager.CreateSubscription(new SubscriptionDescription(topic,subscriptionName) {
        AutoDeleteOnIdle=TimeSpan.FromDays(2)
    });
}
Community
  • 1
  • 1
Vincent
  • 938
  • 13
  • 20