I have an Azure Function with the following content in host.json:
{
"version": "2.0",
"functionTimeout": "01:00:00",
"extensions": {
"serviceBus": {
"SessionHandlerOptions": {
"MaxAutoRenewDuration": "01:00:00",
"MaxLockDuration": "01:00:00",
"MessageWaitTimeout": "01:00:00",
"MaxConcurrentSessions": 1,
"AutoComplete": false
}
}
},
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
On running this function, I see the following exception:
The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.
The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue suggests to set AutoComplete to false. I have already added a property in host.json which sets AutoComplete to false. What am I missing?
Code:
public async Task Run([ServiceBusTrigger("queuename", Connection = "cn")] Message message,
MessageReceiver messageReceiver,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
var syncJob = JsonConvert.DeserializeObject<Job>(Encoding.UTF8.GetString(message.Body));
try
{
await starter.StartNewAsync(nameof(OrchestratorFunction), syncJob);
await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
}
catch (Exception ex)
{
await messageReceiver.DeadLetterAsync(message.SystemProperties.LockToken, deadLetterReason: ex.Message);
}
await _loggingRepository.LogMessageAsync(new LogMessage { Message = $"{nameof(StarterFunction)} function completed" });
}