Search code examples
azure-functionsazureservicebusazure-servicebus-subscriptions

How to stop a ServiceBusTrigger Azure function from listening to a topic subscription?


I want to disable a ServiceBusTrigger Azure function from listening to a topic subscription in the code. Let's call the function 'MyFunction'. Locally in local.settings.json file, I can add this setting and it disables the function completely. local.settings.json doesn't get deployed as it's only used locally by .NET/VS.

  "Values": {
    "AzureWebJobs.MyFunction.Disabled": true
  }

However, I tried to add the same setting in appSettings.json, the setting has no effect. The Azure function was retrieving messages from the topic.

Putting an if statement in the body of the function to stop any processing will still cause the function to read a message from the topic in an endless loop.

AutoCompleteMessages = false also doesn't stop the function from retrieving messages.

How do I disable the azure function from listening to the topic completely?


Solution

  • I didn't mention that my Azure function runs in an app container. Here's how to disable the Azure function.

    • Create a new environment variable in the container app called AzureWebJobs.MyFunction.Disabled where MyFunction is your function name. Give it a value of true or false
    • The environment variable has to be created or modified by creating a new revision of the container and creating/modifying it in the image itself.
    • Once the revision is created, Azure will switch to it and run it. Therefore make sure that what happens.