How to set TTL on ServiceBus ManagementClient CreateSubscriptionAsync

82 Views Asked by At

When I create a subscription as follows the TTL is defaulted to 10675199 days

var client = new ManagementClient(connStr);

if (!await client.SubscriptionExistsAsync(topicName, subscriptionName))
{
    // TODO: this has an unlimited TTL, which needs to be reduced to 1 day.
    client.CreateSubscriptionAsync(topicName, subscriptionName); 
}

How can this be set from code?

1

There are 1 best solutions below

0
On BEST ANSWER

You should use the overloading method of CreateSubscriptionAsync which takes SubscriptionDescription as parameter.

Like below:

var sd = new SubscriptionDescription(topicName, subscriptionName)
{
    DefaultMessageTimeToLive = TimeSpan.FromDays(1)

};

if (!await client.SubscriptionExistsAsync(topicName, subscriptionName))
{
    client.CreateSubscriptionAsync(sd);
}

See here for more details.