skip to Main Content

I have an Azure Function to process messages from Service Bus Queue using ServiceBusTrigger. Deployed host.json file with setting "maxMessageBatchSize": 5 however it’s neglected somehow and the logging indicates it’s using the default value of 1000. I’m not able to change this value no matter what I did.

Here is a snippet of function code

[FunctionName("SomeFunction")]
    public async Task Run(
            [ServiceBusTrigger("queue-name", Connection = "ServiceBusConnectionString")]
            ServiceBusReceivedMessage[] messages,
            ILogger log)                     
    {
        log.LogInformation("Executing Function {}", messages.Length);
        var options = new Microsoft.Azure.WebJobs.ServiceBus.ServiceBusOptions();
        log.LogInformation($" MaxMessageBatchSize: {options.MaxMessageBatchSize}");

and host.json deployed per Extensions 5.x+ documentation here and I tried Functions 2.x+ as well to be sure but no help there either.

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensions": {
    "serviceBus": {
      "prefetchCount": 0,
      "maxConcurrentCalls": 5,
      "maxConcurrentSessions": 5,
      "maxMessageBatchSize": 5
    }
  }
}
  • It’s a .NET 6 project in VS 2022,
  • Microsoft.Azure.Functions.Extensions 1.1.0
  • Microsoft.Azure.WebJobs,Extensions.ServiceBus 5.8.1
  • Microsoft.NET.Sdk.Functions 4.0.1
  • ServiceBus sessions set to disabled
  • Scale Out setting = 1 in Consumption mode

2

Answers


  1. How are you determining that 5 is not being used? When you construct a new options instance in your function body, that will have the default value for the property, but that does not imply that the extension is not honoring the value that you specified in host.json.

    When starting up locally, if you pass the verbose flag you will be able to see the host.json options that are being used, i.e.:

    func host start --verbose
    
    Login or Signup to reply.
  2. For me (tested locally) works host.json with your configuration. I had 20 items on the topic:

    "extensions": {
      "serviceBus": {
        "maxMessageBatchSize": 2
       }
     }
    

    Your code display for me:

    [2023-04-13T13:42:34.777Z] Executing Function 2
    [2023-04-13T13:42:34.783Z]  MaxMessageBatchSize: 1000
    

    There was a discussion about ServiceBusOptions showing wrong values:
    https://github.com/Azure/azure-functions-servicebus-extension/issues/81. But the solution which was on the end didn’t work for me.

    I had a feeling that serviceBus => maxMessageBatchSize is the configuration for extension 5+ and not for Azure Function 2+. The code which you tried to run is related to getting data from Azure Function 2+ configuration and because of that you don’t get values from Extension 5+.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search