Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure service bus - Renew lock is not working properly

Sometimes lock is not being renewed automatically. Please let me know if i am doing any mistake. I am using Microsoft.Azure.ServiceBus library (v3.4.0) and below is my code snippet.

var client = new QueueClient(connectionString, queueName, ReceiveMode.PeekLock);
            client.RegisterMessageHandler(async (message, token) =>
            {
                var logger = new AzureLogger();
                logger.Debug("----------------------------------------------------------------------------");
                logger.Debug("Message received.");
                var body = Encoding.UTF8.GetString(message.Body);
                logger.Debug($"Message : {body}");
                try
                {
                    for (int i = 1; i <= 30; i++)
                    {
                        logger.Debug(i.ToString());
                        logger.Debug("Lock time: " + message.SystemProperties.LockedUntilUtc.ToString("yyyy-MM-dd hh:mm:ss"));
                        logger.Debug("Lock token info: " + message.SystemProperties.IsLockTokenSet);
                        logger.Debug("Lock token: " + message.SystemProperties.LockToken);
                        Thread.Sleep(60000);
                    }
                    logger.Debug("Processing completed.");
                    await client.CompleteAsync(message.SystemProperties.LockToken);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    logger.Error(ex.StackTrace);
                    await client.DeadLetterAsync(message.SystemProperties.LockToken);
                }
            }, new MessageHandlerOptions(LogMessageHandlerException)
            {
                AutoComplete = false,
                MaxAutoRenewDuration = TimeSpan.FromMinutes(120)
            });

log enter image description here

like image 361
Hasnu zama Avatar asked Dec 11 '25 15:12

Hasnu zama


1 Answers

Lock renewal is not a guaranteed operation. It's a client-side operation/request which when fails, will not be able to extend the lock. You have to keep that in mind when relying on this feature.

like image 135
Sean Feldman Avatar answered Dec 13 '25 05:12

Sean Feldman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!