Reputation: 8741
I'd like an azure function that's triggered from an Azure storage account queue to run as a singleton.
The function app is in-process and net6:
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
My function currently looks as follows:
[FunctionName(nameof(QueueTrigger))]
[Singleton(Mode = SingletonMode.Listener)]
public async Task QueueBatch([QueueTrigger("TriggerSurvey")] TriggerMsg triggerMsg)
Following the suggestion from @Moho I added the following to the host.json and the Singleton method decorator as now shown above but this made no difference to the behaviour of the app.
"extensions": {
"queues": {
"maxPollingInterval": "00:00:02",
"visibilityTimeout": "00:00:30",
"batchSize": 1,
"maxDequeueCount": 5,
"newBatchThreshold": 8,
"messageEncoding": "base64"
}
}
I tested as follows: I published a message to the queue. The function consumed this and began its work - writing to Azure Sql. This job took approx 3 minutes and it inserted a log table many times as it worked, along with a correlation id for the function instance. After a few seconds of publishing the first message I published a second. From the log table I could see that a different function instance had consumed and was processing concurrently with the first.
Anyone know how to configure so that only one instance of the function will ever poll the queue?
Upvotes: 3
Views: 3704
Reputation: 16553
The batch size and the threshold for getting a new batch are configurable in the host.json file. If you want to minimize parallel execution for queue-triggered functions in a function app, you can set the batch size to 1. This setting eliminates concurrency only so long as your function app runs on a single virtual machine (VM).
host.json > extensions > queues > batchSize
Upvotes: 2