3

我正在尝试从 Azure 应用程序配置读取 eventthubname 和连接字符串,而不是函数应用程序设置,但我无法让它工作,如果我从函数应用程序本身它工作正常,但我需要从应用程序配置集中配置存储读取.

到目前为止,这是我的小功能

  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)
        {
           
        }
    }

但这不起作用,因为 _config 变量没有对象引用,所以它有点问题 22

如何正确读取这些配置设置?

4

3 回答 3

1

下面是如何从 Azure 应用配置中获取队列名称并将其用于 QueueTrigger 的示例。您应该能够为 EventHubTrigger 做类似的事情。它使用应用程序设置绑定表达式。请注意,由于 Azure Functions 的限制,消费计划不支持此功能。

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

于 2021-06-12T06:40:27.437 回答
0

您需要使用dependency injection并添加Azure App Configuration为额外的配置源,以便您的应用程序功能与之对话。

您可以按照启动时的快速入门指南进行注册。

于 2021-06-12T08:01:30.177 回答
-1

使用此代码:

Environment.GetEnvironmentVariable("something");
于 2021-06-02T07:08:27.230 回答