Auto-expire orphaned Subscription (Azure ServiceBus Messaging SubscriptionClient)

前端 未结 3 1328
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 02:37

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

相关标签:
3条回答
  • 2021-01-12 03:19

    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://docs.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.subscriptiondescription

    0 讨论(0)
  • 2021-01-12 03:30

    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);
    
    0 讨论(0)
  • 2021-01-12 03:39

    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)
        });
    }
    
    0 讨论(0)
提交回复
热议问题