Search code examples
node.jsazureazure-storageazure-functionsazure-storage-queues

Disabling Azure Function multiple simultaneous triggers


I have an Azure Function App with 7 Functions written in Node.js, deployed though Bitbucket CI and the following host.json-file at the root of the project:

{
    "id": "...",
    "queues": {
        // retrieve only 1 queue message at a time
        "batchSize": 1,
        "maxDequeueCount": 1,
        "newBatchThreshold": 0
    }
}

As far as I know, this should make sure that only 1 queue-triggered function is triggered at a time.

However, If I put the following statement in my function:

context.log(`Started processing at ${new Date()}`);

I still have some cases with the exact same start time for 2 queue messages.

Any idea what I am missing? Is this batchSize property used per function or per queue?


Solution

  • If you look in the host.json documentation, you can see that batchSize is per (job) function.

    Here's where Azure Functions pulls the batch, in queue listener.

    There is a separate queue listener created per QueueTrigger binding, so batchSize is per-function. In this case, as you have 7 functions triggering from the same queue, you could have as many as 7 queue messages processing simultaneously on this instance in separate function executions.

    I verified by writing a webjobs console app that has two functions triggered from the same queue. I could see that there were two separate QueueListener objects (via GetHashCode), one for each function, listening on the same queue simultaneously.

    Why do you want to disable simultaneous execution?