2

I am using Azure App Configuration Store to store configuration. I am using the following code in startup.cs to load my config from Azure.

var builder = new ConfigurationBuilder();

            builder.AddAzureAppConfiguration(options =>
            {
                options.Connect(this.Values.AppConfigConnectionString);
                options.Select(keyFilter: KeyFilter.Any, labelFilter: this.Values.Env);
            });

            var config = builder.Build();

Now this config variable contains my queue names. I need this dynamic so to create and handle it in 4 different environments. Dev / Stage / QA / Prod.

public async Task Run(
            [QueueTrigger("%QueueName%", Connection = "StorageConnection")]VoiceHubEvent item)

This isn't working as my local.settings.json file doesn't contain QueueName entry.

Is it possible to make use of config variable in Run() to resolve queuename? By reloading queue trigger function or something?

Thanks, Kiran.

Jessica
  • 167
  • 2
Max
  • 1,528
  • 21
  • 33
  • Does this answer your question? [How to set Azure WebJob queue name at runtime?](https://stackoverflow.com/questions/22721491/how-to-set-azure-webjob-queue-name-at-runtime) – Anton Apr 20 '20 at 10:38
  • No, I already have queue name from local.settings.json // But I want to load queue name from online azure app config. This - https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-dotnet-core-app – Max Apr 20 '20 at 12:50
  • Suppose there is a tutorial about how to connect azure function with app configuration.https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-azure-functions-csharp – George Chen Apr 21 '20 at 06:25

1 Answers1

0

Is it possible to make use of config variable in Run() to resolve queuename? By reloading queue trigger function or something?

Yes, you can.

Create an extensions method for the IWebJobsBuilder interface to set up a connection to AzureAppConfiguration.

public static IWebJobsBuilder AddAzureConfiguration(this IWebJobsBuilder webJobsBuilder)
{
     //-- Get current configuration
     var configBuilder = new ConfigurationBuilder();
     var descriptor = webJobsBuilder.Services.FirstOrDefault(d => d.ServiceType == typeof(IConfiguration));
     if (descriptor?.ImplementationInstance is IConfigurationRoot configuration)
         configBuilder.AddConfiguration(configuration);

     var config = configBuilder.Build();

     //-- Add Azure Configuration
     configBuilder.AddAzureAppConfiguration(options =>
     {
         var azureConnectionString = config[TRS.Shared.Constants.CONFIGURATION.KEY_AZURECONFIGURATION_CONNECTIONSTRING];

         if (string.IsNullOrWhiteSpace(azureConnectionString)
                    || !azureConnectionString.StartsWith("Endpoint=https://"))
             throw new InvalidOperationException($"Missing/wrong configuration value for key '{TRS.Shared.Constants.CONFIGURATION.KEY_AZURECONFIGURATION_CONNECTIONSTRING}'.");

         options.Connect(azureConnectionString);
     });
     //build the config again so it has the key vault provider
     config = configBuilder.Build();


     return webJobsBuilder;
 }

Where the azureConnectionString is read from you appsetting.json and should contain the url to the Azure App Configuration.

In startup.cs:

    public void Configure(IWebJobsBuilder builder)
    {
        builder.AddAzureConfiguration(); 
        ConfigureServices(builder.Services)
            .BuildServiceProvider(true);
    }

For more details, you could refer to this SO thread.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Hi, even if I load Azure App Config here, how will I reference queuename in my queue function? Here at `"%QueueName%"` – Max Apr 21 '20 at 13:17
  • You can extract the values from my Azure App Configuration exactly as if they where written in your appsetting.json file. – Joey Cai Apr 23 '20 at 02:52