ZZZSharePoint
ZZZSharePoint

Reputation: 1361

Where do I specify MaxConcurrent calls in Azure Service bus

Below is my Azure Function App code which triggers on a Service bus topic. After certain delay, I run across this error in my console "The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. while removing message".

On googling and referring other stack overflow posts, one solution that has been asked to try is specifying the Maxconcurrent calls but I couldn't figure out where do I specify that and how do I do it in my below code. If someone can help me on that and also if any other alternative I should try for this error.

 public class TabularData
{
    

    [FunctionName( "ProcessTableData" )]
    public async Task Run( [ServiceBusTrigger("twister-events", "tabulardata-processor",
        Connection = "AzureServiceBusString")]
        string SbMsg, ExecutionContext context,
        ILogger log )
    {
        try
        {
            MyProject.CreateDefaultLoggerFactory();
            TableStorageManager manager = new TableStorageManager();
            if( !string.IsNullOrEmpty( SbMsg ) )
            {
                log.LogInformation( $"C# ServiceBus topic trigger function processed message: {SbMsg}" );
                TableStorageConfiguration rulesList = GetConfiguration( context.FunctionAppDirectory, "DataFileConfiguration.json" );
                await ProcessServiceBusMessage( SbMsg, rulesList, manager );
            }
        }
        catch( Exception Ex )
        {
            log.LogError( $"Error while uploading tabular data; {Ex.Message}" );
            throw;
        }
    }

UPDATE: This is how my host.json file looks like but I still running into same error.

{
  "functionTimeout": "05:05:00",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "prefetchCount": 100,
      "messageHandlerOptions": {
        "autoComplete": false,        
        "maxConcurrentCalls": 32,
        "maxAutoRenewDuration": "05:00:00"
      },
      "sessionHandlerOptions": {
        "autoComplete": false,
        "messageWaitTimeout": "05:00:30",
        "maxAutoRenewDuration": "05:55:00",
        "maxConcurrentSessions": 16
      }
    }
  }

Upvotes: 0

Views: 1902

Answers (1)

Jdresc
Jdresc

Reputation: 688

The error basically means that the Function App couldn't process the message during the lock duration time which is 30 seconds by default, an alternative solution would be to increase to lock duration from 30 to 60 and see if that helps on decreasing the amount of lock invalid exceptions. Regarding where to specify the "maxConcurrentCalls" that is done in the host.json settings file

 },
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "maxConcurrentCalls": "1"
    }
  }
} 

Upvotes: 1

Related Questions