'Unable to limit the maximum number of concurrent service bus messages processed at a time
I am using Azure Functions 3.0.13 and referring to the documentation provided
I have one TimerTrigger that runs daily that puts 0...N messages on the service bus that is then processed by a function with a ServiceBusTrigger that consumes said messages.
Using the host.json input provided, however, I can see that all messages are processed at the same time regardless of setting maxConcurrentCalls to 1.
This is causing all functions to run in parallel and resulting in a deadlock on my database.
I can use the decorator [Singleton(Mode = SingletonMode.Function)] to run one at a time however this is affecting my throughput and I would rather be able to control how many messages can be processed in parallel at a time.
Am I misinterpreting the documentation or is this a bug?
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true
}
}
},
"functionTimeout": "01:00:00",
"extensions": {
"serviceBus": {
"prefetchCount": 1,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 1,
"maxAutoRenewDuration": "00:05:00"
},
"batchOptions": {
"maxMessageCount": 1,
"operationTimeout": "00:05:00",
"autoComplete": true
}
},
"durableTask": {
"maxConcurrentActivityFunctions": 5,
"maxConcurrentOrchestratorFunctions": 1
}
}
}
Edit 1:
Sessions are not enabled on the service bus subscription,

Solution 1:[1]
I believe this is a bug in limiting the maximum number of concurrent service bus messages processed at a time. As the few workarounds gives the information like:
maxConcurrentSessionssetting to1in the host.json helps to limit around20messages at a time. The Functions runtime processes multiple messages concurrently by default.
{
"version": "2.0",
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 1,
"maxAutoRenewDuration": "00:05:00"
},
"sessionHandlerOptions": {
"autoComplete": true,
"messageWaitTimeout": "00:00:30",
"maxAutoRenewDuration": "00:55:00",
"maxConcurrentSessions": 1
}
}
}
}
Here the prefetchCount value is set to 100.
Prefetching messages increases the overall throughput for a queue or subscription because it reduces the overall number of message operations, or round trips. Fetching the first message, however, will take longer (because of the increased message size). Receiving prefetched messages from the cache will be faster because these messages have already been downloaded by the client.
References:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HariKrishnaRajoli-MT |

