Do Azure Functions triggered by storage queue take single message or all messages?
Asked Answered
F

3

6

If I create an Azure Function that is triggered by storage queue messages... will the system launch multiple parallel functions to reach each message from the queue or will a single function get called that reads in all available messages?

In short, are queued messages handled individually or in batches?

Filtration answered 25/6, 2017 at 18:5 Comment(0)
B
11

API-wise your function will be called once per each individual message in the queue.

But Azure Functions runtime will retrieve and process messages in batches, calling several instances of your function in parallel.

Baguio answered 25/6, 2017 at 18:58 Comment(4)
But only if they come in fast enough right. I think it's not possible to configure the time window in which they're processed? I'd actually like to force a batch because if a particular client sends two messages in quick succession I actually want to just ignore the first.Majolica
@Majolica Correct.Baguio
Oh! Glad I reread your answer. Need to make sure they don't get processed in the wrong order! Regarding sequential processing this may help others feedback.azure.com/forums/355860-azure-functions/suggestions/…Majolica
Are there resources shared across the parallel function instances? E.g. if I declare a static member or singleton, will the functions share it? Or do they all do a "cold start" loading up references and everything?Kwang
A
6

First, as Mikhail said, Azure Functions runtime retrieve and process queue messages in batches. And the default batchSize is 16 and the maximum batchSize is 32

Besides, we can do configuration for 'queue' triggers and specify/modify batchSize in host.json file.

Configuration settings for 'queue' triggers

"queues": {
  "maxPollingInterval": 2000,
  "visibilityTimeout" : "00:00:10",
  "batchSize": 16,
  "maxDequeueCount": 5,
  "newBatchThreshold": 8
}
Amaryllis answered 29/6, 2017 at 9:27 Comment(1)
So does your function receive an array or an individual message? If an array, how do you allow one to fail and be retried without failing the whole batch?Kwang
E
1

It doesn't handle all the messages in one go but it supports message batching. In order to enable batching you need to make the function's input an array of the type rather than the type itself. (e.g. EventData[] rather than EventData) then the batching applies. You can set the batch size up to 32 as @Fei mentioned. Checkout the following link talks about it briefly:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-best-practices

Exceeding answered 10/1, 2018 at 22:57 Comment(2)
This is only for EventHub trigger binding according to the link you sharedCognoscenti
Confirmed what @Cognoscenti said - does not work with Storage Queues. Cannot read in batches.Dah

© 2022 - 2024 — McMap. All rights reserved.