1

Is there a way to tell the host to stop picking up messages from the queue? Or is there a hook in the service bus extension we can use to stop messages from being picked up?

There are two use cases I can think of. Graceful shutdown and also if we detect our database is unavailable. If the DB is unavailable there's no point trying to process messages, but if we can't tell it to stop picking up messages then all those messages will end up in the DLQ, even though they are most likely perfectly valid.

We use a ServiceBusTrigger and in our startup code we call host.UseServiceBus(), this nicely automatically picks up messages from the queue.

If we call host.Stop(), then it obviously stops picking up messages from the queue. Unfortunately it also stops all processing that may be in progress. We want to ensure any in progress processing completes before calling stop.

wallismark
  • 1,766
  • 2
  • 21
  • 35

1 Answers1

0

Suppose you just want to disable a specific webjob function and else still work. If yes there are two ways to implement it.

Firstly use Disable property to do it, add a Disable to your appsettings.json file, this method lets you enable and disable the function by changing the app setting.

enter image description here

Another way is add "AzureWebJobs.YourFunctionName.Disabled": "true" to appsettings.json file to disable function.

enter image description here

Below is my test result, both two functions are disabled.

enter image description here

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • Thank you for your clear answer, I didn't know about those settings. Unfortunately they are startup only settings, I need to be able to tell the webjob to stop receiving messages dynamically at runtime. – wallismark May 12 '20 at 13:17
  • There is a `Cancellation tokens` parameter to cancel webjob.https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#cancellation-tokens – George Chen May 13 '20 at 06:36