0
votes

I have an web job that consumes message from Azure Service Bus Topic by registering a OnMessage callback . The message lock duration was set to 30 seconds and the lock renew timeout to 60 seconds. As such jobs taking more than 30 seconds to process service bus message were getting lock expired exception.

Now,I have set the message lock duration to more than lock renew time out. But somehow it still throws same exception. I also restarted my webjob, but still no luck.

I tried running same webjob consuming messages from different topic with later settings and it works fine. Is this behaviour expected, and after how much time does this setting change normally reflect.

Any help will be great

2

2 Answers

3
votes

I have set the message lock duration to more than lock renew time out. But somehow it still throws same exception.

The max value of lock duration is 5 min. If you need less than 5 min to process the job, you could increase the lock duration of your message to meet your requirement.

If you need more than 5 min to process your job, you need to set the AutoRenewTimeout property of OnMessageOptions. It will renew the lock if the lock expired before it reached the AutoRenewTimeout. For example, if you set lock duration to 1 min and set AutoRenewTimeout to 5 min. The message will keep in locked for up to 5 min if you don't release the lock.

Here are the sample code I used to test the lock duration and AutoRenewTimeout on my side. If the job spent more time than lock duration and AutoRenewTimeout, it will throw a exception when we complete the message(it means timeout happened). I also modified the lock duration on portal and the configuration will be applied immediately when I receive a message.

SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString(connectionString, "topic name", "subscription name");

// Configure the callback options.
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromSeconds(60);

Client.OnMessage((message) =>
{
    try
    {
        //process the message here, I used following code to simulation a long time spent job
        for (int i = 0; i < 30; i++)
        {
            Thread.Sleep(3000);
        }
        // Remove message from subscription.
        message.Complete();
    }
    catch (Exception ex)
    {
        // Indicates a problem, unlock message in subscription.
        message.Abandon();
    }
}, options);

For your issue, please check how much time will be spent on your job and choose a right way to set lock duration and AutoRenewTimeout.

1
votes

The settings should be reflected almost immediately. Also lock renewal should probably be more than the lock duration or disabled.

Lock renewal feature is ASB client feature and it doesn't override lock duration set on entities. If you can reproduce this issue and share the repro, raise a support issue with Microsoft.