4

I am trying to read the eventhubname and connection string from Azure App Configuration, NOT function app settings, but I cannot get this to work, if I real from the function app itself it works fine but I need to read from App Configuration centralized configuration store.

Here is my small function so far

  public class CDSSoftDelete
    {
        static string _eventHubname = null;
        string _connectionString;
        private readonly IConfiguration _config;

        public CDSSoftDelete(IConfiguration config, IConfigurationRefresher configurationRefresher)
        {
            if (config == null) throw new ArgumentNullException(nameof(config));
            if (configurationRefresher == null) throw new ArgumentNullException(nameof(configurationRefresher));

            configurationRefresher.TryRefreshAsync();

            _config = config;

            _eventHubname = config["SLQueueManager:Settings:EventHubName"];
            _connectionString = config["SLQueueManager:Settings:EventHubConnectionString"];
        }

        [FunctionName("CDSSoftDelete")]
        public async Task Run([EventHubTrigger(_config["SLQueueManager:Settings:EventHubName"], Connection = _connectionString)] EventData[] events, ILogger log)
        {
           
        }
    }

But this does not work because the _config variable does not have an object reference, so its a bit of a catch 22

How can I read those config settings correctly ?

Matt Douhan
  • 2,053
  • 1
  • 21
  • 40

3 Answers3

2

Here is an example of how to get queue name from Azure App Configuration and use it for QueueTrigger. You should be able to do something similar for EventHubTrigger. It uses app setting binding expression. Please note that this is not supported in the consumption plan due to limitations in Azure Functions.

https://github.com/Azure/AppConfiguration/blob/main/examples/DotNetCore/AzureFunction/FunctionApp/ReadQueuedMessage.cs

Zhenlan Wang
  • 1,213
  • 8
  • 10
  • Hi @Zhenlan, can we do the same for Eventhub connectionstring too? I tried to do what was suggest but it wouldn't work even for EventHubName – wenn32 Oct 29 '21 at 01:37
0

You need to use dependency injection and add Azure App Configuration as extra configuration source in order for your app function talk with it.

you can follow the quick start guideline in your startup register them.

Turbot
  • 5,095
  • 1
  • 22
  • 30
-1

Use this code:

Environment.GetEnvironmentVariable("something");
Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • how will that fetch the keys from my central confid store? I know this works for local settings but seems not to work from app config stire – Matt Douhan Jun 02 '21 at 07:10
  • @MattDouhan Don't you set app settings in [this place](https://i.stack.imgur.com/v4djn.png)? In fact, the trigger or bindings get configuration from the environment variables(The above 'application setting' will been read to environment variables). If you set the environment variables before function start, then the attribute of eventhubtrigger should be able to get the settings. – Cindy Pau Jun 02 '21 at 07:31
  • 1
    @boman no, I specifically said in the question I am not using local app settings, I am usingthe centralized app configstore service in Azure, I know this works for the local store but thats not what the question is about. – Matt Douhan Jun 02 '21 at 07:32