Hello Bhavin Dave,
Thanks for posting your question in the Microsoft Q&A forum.
Let's go through the steps to configure batch processing correctly:
Update host.json: Ensure your host.json file includes the following configuration for Service Bus:
{
"version": "2.0",
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 16,
"maxAutoRenewDuration": "00:05:00"
},
"batchOptions": {
"maxMessageCount": 1000,
"operationTimeout": "00:00:30"
}
}
}
}
Update Function Code: Modify your Azure Function to handle batches of messages. Here's an example in C#:
[FunctionName("ServiceBusBatchTrigger")]
public static async Task Run(
[ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")] ServiceBusReceivedMessage[] messages,
ILogger log)
{
foreach (var message in messages)
{
log.LogInformation($"Processed message: {message.Body}");
}
}
Batch Size: The actual number of messages in a batch may vary depending on the current load and message availability. Azure Functions will try to optimize based on your settings and the current state of the queue
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful