Configuring maxConcurrentCalls for a Specific Azure Function in a Function App

Pedro Ferreira 25 Reputation points
2024-10-23T13:43:46.09+00:00

Hi everyone,

I have an Azure Function App that contains multiple functions, all related to the same business case. These functions are triggered by a Service Bus trigger. For one of these functions, I need to ensure it processes one message at a time — meaning it should pick up a message, process it, and only then move to the next one.

I've come across the following configuration in host.json:

"extensions": {
  "serviceBus": {
    "messageHandlerOptions": {
      "maxConcurrentCalls": 1
    }
  }
}

However, setting this will apply the configuration globally across all the functions in the Function App. My goal is to restrict this setting to just one function while keeping the rest of the functions running with their default concurrency settings.

From what I understand, using a Singleton attribute would only prevent other functions (say Function A and Function B) from running while the specific function (Function C, the one that needs to process one message at a time) is executing. But that's not what I'm aiming for.

I’m trying to avoid creating another Function App just to configure the maxConcurrentCalls for this one function. Is there any alternative approach that allows me to configure this behavior for a single function within the same Function App?

Thank you in advance for any suggestions!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
Developer technologies | C#
{count} vote

Accepted answer
  1. JananiRamesh-MSFT 29,261 Reputation points
    2024-10-24T08:10:11.0566667+00:00

    @Pedro Ferreira Thanks for reaching out. Like most settings in host.json, maxConcurrentCalls is a host-level setting, and it applies to all Service Bus triggers in the function app. If a different value is needed for one particular function, its recommended that function needs to be moved to a different function app.

    If the Singleton attribute is applied to a function, other functions are not affected. There are two modes.

    The function mode (default): Invocations are serialized, so that only one invocation is executed at a time, even across instances (if the function app is scaled out to multiple instances).

    The listener mode: Invocations are serialized, so that only one invocation is executed at a time, and they happen only on a single instance.

    The Singleton attribute can be considered, but the behavior described above must be taken into account. More specifically, if the function app runs on a single instance and the desired concurrency is 1, then the attribute would do the trick.

    do let me know incase of further queries, I would be happy to assist you.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.