Search code examples
azureazure-functionsazure-servicebus-queues

Azure function service bus trigger: How to stop batches of data from event stream and only allow one message from the queue at a time?


This is my first time using Azure functions and service bus.

I'm trying to build a function app in Visual Studio and I am able to connect to the queue topic (which I don't control). The problem is that every time I enable a breakpoint, 10s of messages are processed at once in VS which is making local testing very difficult (not to mention the problems arising from database pools).

How do I ensure that only 1 message gets processed at once until I hit complete?

public static void Run([ServiceBusTrigger("xxx", "yyy", AccessRights.Manage)]BrokeredMessage msg, TraceWriter log)
{
     // do something here for one message at a time.
}

Solution

  • Set maxConcurrentCalls to 1 in the host.json. You also could get answer from host.json reference for Azure Functions

    maxConcurrentCalls 16 The maximum number of concurrent calls to the callback that the message pump should initiate. By default, the Functions runtime processes multiple messages concurrently. To direct the runtime to process only a single queue or topic message at a time, set maxConcurrentCalls to 1