.nettriggersazure-functionsqueuetrigger

Select Azure Function trigger at runtime or compile time


I have set of Azure functions with QueueTrigger triggers on them. The goal is to support another cloud platform (e.g KafkaTrigger) depending on the configuration or at least as a build pipeline step.

Approaches I have come up with:

  1. Create a custom trigger and reuse underlying objects from both QueueTrigger and Kafka trigger.

I haven't found to achieve this, and even if I had, the underlying QueueTrigger objects are primarily internal.

  1. Generate the trigger attributes as a pre-build action.

Probably would work, but I am trying to find a better solution.

  1. Having two sets of functions and disabling one of them depending on configuration.

Again, doesn't seem like a good approach. Will require either a code generation for Disable attribute or some hack logic.

Question:

Is there a better way to achieve this? Maybe creating a custom trigger is a viable option and I am missing something?


Solution

  • You can disable a function via app settings.

    The recommended way to disable a function is with an app setting in the format AzureWebJobs.<FUNCTION_NAME>.Disabled set to true.

    So with common code extracted out and two differently triggered functions, you can simply update app settings to activate the function that you want.

    Considering the simplicity here, I don't believe the other solutions are worth the effort unless you want to integrate the functionality of disabling/enabling functions via another system automatically. Even then, you are likely better off to extract the automation into another function app.