2

I am using latest version of .net sdk (Azure.Messaging.ServiceBus).

I want to renew the lock duration of the message since processing of messages takes more than 5 min so that other listeners/consumers to the client cant receive while one of the listner/consumer processing message. I have tried by setting MaxAutoLockRenewalDuration property , but it didnt work, after 5 min other consumer is consuming the message before compelting the current consumer.

Sample code which i have used

  var client =  CreateQueueClient("managedQueue");
        var proc = client.CreateProcessor("managedQueue", options: new ServiceBusProcessorOptions
        {
            MaxConcurrentCalls = 2,
            AutoCompleteMessages = false,
            ReceiveMode = ServiceBusReceiveMode.PeekLock,
            MaxAutoLockRenewalDuration = new TimeSpan(0,20,0), 
        }) ;
        proc.ProcessMessageAsync += MessageHandler;
        proc.ProcessErrorAsync += ErrorHandler;

Sample Callback Code

async Task MessageHandler(ProcessMessageEventArgs args)
    {
        try
        {
            string body = args.Message.Body.ToString();
            Console.WriteLine($"Received: {body}");
           
            await Task.Delay(480000);//8 min
              // complete the message. messages is deleted from the queue. 
            await args.CompleteMessageAsync(args.Message);
        }
        catch(Exception ex)
        {
            Console.WriteLine("Exception In Handler:"+ex);
        }
       
    }

Can you please any one help me regarding this auto renew the lock duration of the message.

Thanks

cva
  • 99
  • 9
  • What do you mean "after 5 min consumer is consuming the message"? Is your message completed with errors? The configuration blooms right. – Sean Feldman Aug 05 '21 at 13:58
  • @SeanFeldman sorry for the typo, I have updated ,after 5 min other consumer is consuming the message, so duplicate processing with multiple consumers and message wont get complete, it always be there in queue. – cva Aug 05 '21 at 14:12
  • @SeanFeldman so i want auto renew the lock duration ,so that one consumer process it and then complete the message. – cva Aug 05 '21 at 14:14
  • AutoCompleteMessages is set to `false`. Are you completing manually in your callback? If not, that could be the issue. Would help to see that callback code. – Sean Feldman Aug 05 '21 at 14:14
  • @SeanFeldman Yes i am completing message manually once processing is done. Updated the callback code .Please refer – cva Aug 05 '21 at 14:17
  • I wish you'd provide a repro and not snippets. Your first part is missing `await proc.StartProcessingAsync();` for example to get the processor actually to work. In terms of the code - it works (assuming there's nothing else that'd be important to see). – Sean Feldman Aug 06 '21 at 07:12
  • @SeanFeldman Yes i do have start the proc.StartProcessingAsync(), it got missed in code snippet,my worry is that how to auto renew the lock duration of the message if processing takes more than 5 min since we have only max 5 min lock duration for the queue. – cva Aug 06 '21 at 08:04
  • I ran the code and it worked as expected. A repro would help. – Sean Feldman Aug 06 '21 at 13:39
  • @SeanFeldman Hi, Here is the code sample https://github.com/cvakarna/servicebus_issue/blob/main/ServicebusSample/Program.cs repo – cva Aug 09 '21 at 07:03
  • I've ran a similar code, just w/o try/catch and in an asynchronous main method and it worked as expected. – Sean Feldman Aug 11 '21 at 22:28
  • So there's still no answer for this? Currently migrating from .NET Core 3.1 to .NET 6 and lack of support for manual renewal in Triggered functions and this issue are requiring us to look into scaffold around it. – Captain Prinny Feb 03 '22 at 18:47
  • I am also looking for how to manage auto renewal message before it will be timeout @CaptainPrinny – Furqan Misarwala Jan 29 '23 at 18:50

0 Answers0