4

I have an Azure Service Bus triggered Azure Function. When I run the Azure Function locally, it starts 16 threads and picks up 16 messages in each thread. How can I configure it so that it only runs one message so that I can debug it without the same breakpoint getting hit 16 times?

I tried to set configuration in host.json file (as below) to only pick up 1 message at a time from Azure Service Bus, but this didn't help.

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "prefetchCount": 100,
      "messageHandlerOptions": {
        "autoComplete": false,
        "maxConcurrentCalls": 1,
        "maxAutoRenewDuration": "00:55:00"
      }
    }
  }
}

Edit 1: What I currently do is triggering the function's admin endpoint via an http request that contains message input in body. The problem with this is that the http request body has to contain {"input":"{}"} and I have to spend time creating valid json every time with escaped double quotes. Would be much easier if I was able to configure the function to run single message at at time from service bus topic.

tubakaya
  • 457
  • 4
  • 15
  • maxConcurrentCalls does exactly that. Also, you don’t need the prefetch of 20. Since it’s a local environment, can you post a single message and have only one in your queue? That will also work regardless of the concurrency. – Sean Feldman Feb 22 '20 at 16:30
  • But this host.json doesn't make any difference for me. It still picks up 16 messages. I don't want to deal with how many messages are sent to service bus topic. I am looking for a way to retrieve 1 message at a time while debugging. – tubakaya Feb 22 '20 at 19:06
  • 1
    When your breakpoint hits the first time just remove the breakpoint - you'll be able to carry on for that particular trigger with step into/over etc., and you should see it continues for the same trigger even when stepping into/over await calls and so forth. – Kristin Feb 22 '20 at 23:38
  • 1
    I don't know why host.json doesn't work for you (raise an issue in GitHub). A single message in the queue should work regardless of the concurrency. – Sean Feldman Feb 23 '20 at 01:07
  • Maybe you could try the singleton property or share your code. And what do yo mean you are triggering via http request? You said it's service bus trigger function. – George Chen Feb 24 '20 at 08:46
  • With http request I mean calling the admin api. On a service bus triggered function, one can still trigger via http by making a request to admin endpoint of the function. That's what I mean. Singleton attribute didn't work either and also I do not want to use that because then I would have to make sure not to commit that. – tubakaya Feb 24 '20 at 13:06
  • @SeanFeldman, I will open a ticket on github. Thanks for verifying that my understanding of maxConcurrentCalls setting in host.json is correct. – tubakaya Feb 24 '20 at 13:07

3 Answers3

0

For queue-triggered Functions, host.json should be:

{
  "version": "2.0",
  "extensions": {
    "queues": {
      "batchSize": 1
    }
  }
}
Don Cheadle
  • 5,224
  • 5
  • 39
  • 54
anacrust
  • 1,092
  • 8
  • 4
0

Turned out I was making a mistake in how I ran the function (feeling ashamed..). Host.json file was not copied to the bin folder and therefore not recognized. The host.json configuration does work as expected and restrict the function to process one message at a time.

tubakaya
  • 457
  • 4
  • 15
0

try setting this in your local.settings.json to override your host.json file. This way your don't need to change your host.json which prevents you from accidentally commit changes to host.json.

{
   "Values": { 
   "AzureFunctionsJobHost__extensions__serviceBus__messageHandlerOptions__maxConcurrentCalls": 1
   }
}

the result is that your host.json (at runtime) will be changed into this

"extensions": {
  "serviceBus": {
   "messageHandlerOptions": {
    ...
    "maxConcurrentCalls": 1 -> added setting
    ...
  }
}

}

hannes neukermans
  • 12,017
  • 7
  • 37
  • 56