Firstly, we need to make sure that we are at latest version, if not, please upgrate it.
Make sure you add retry policy in function.json
as below:
{
"disabled": false,
"bindings": [
{
....
}
],
"retry": {
"strategy": "fixedDelay",
"maxRetryCount": 4,
"delayInterval": "00:00:10"
}
}
Along with it check for dead letter and configure it with help of MS Docs.
We need to mentioned the lock duration for renewal after it expires in host.json by including the parameter in JSON structure "maxAutoLockRenewalDuration
": "00:05:00"
Below is the example for host.json
{
"version": "2.0",
"extensions": {
"serviceBus": {
"clientRetryOptions":{
"mode": "exponential",
"tryTimeout": "00:01:00",
"delay": "00:00:00.80",
"maxDelay": "00:01:00",
"maxRetries": 3
},
"prefetchCount": 0,
"autoCompleteMessages": true,
"maxAutoLockRenewalDuration": "00:05:00",
"maxConcurrentCalls": 16,
"maxConcurrentSessions": 8,
"maxMessages": 1000,
"sessionIdleTimeout": "00:01:00"
}
}
}
From the above JSON, change the parameter of autoCompleteMessages
from true to false as "autoCompleteMessages": false.
When set to false, you are responsible for calling MessageReceiver methods to complete, abandon, or deadletter the message. If an exception is thrown (and none of the MessageReceiver methods are called), then the lock remains. Once the lock expires, the message is re-queued with the DeliveryCount incremented and the lock is automatically renewed.
Using ReceiveandLock has solved the issue in this case
Refer to these SO thread: SO1 and SO2 (thanks to the answered authors for detailed explanations)