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

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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With