0

I receive a message from Service Bus in ReceiveAndDelete mode and start running a very long computational process which after completion sends a mail. I have error logging in all my methods in my long running method. However the method runs for 10-15 minutes and becomes unresponsive after that neither it logs an error not it sends an email. I wonder it could be something to do with the TTL of the message.

Please advise what should I do?

    private static async Task ProcessMessagesAsync(Message message, CancellationToken token)
    {
       try
         {

           IQueueClient queueClient = new QueueClient(serviceBusConnectionString, serviceBusQueueName, ReceiveMode.ReceiveAndDelete);


            var receivedMessageTrasactionId = Convert.ToInt64(Encoding.UTF8.GetString(message.Body));

            // Very Long Running Method  
            await DataCleanse.PerformDataCleanse(receivedMessageTrasactionId);
                         // to avoid unnecessary exceptions.
          }

        catch (Exception ex)
        {
          Log4NetErrorLogger(ex);
          throw ex;
        }
    }

1 Answers1

0

When receiving a message in ReceiveAndDelete mode, message's Time to Live doesn't matter. Once a message is received on the client side, it will be removed from the broker. In case of an error the message is gone. That's why it's recommended to use PeekLock receive mode when you want to have a safer mechanism of retrieving and processing messages. The caveat is with the processing time. I'm not going to get into that as there's enough information, but you could either renew message's lock or offload processing to eliminate the need in lock renewal. You'll find alternatives in this answer.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80