Azure功能-仅将云中的应用程序设置中的连接字符串用于队列触发

Azure功能-仅将云中的应用程序设置中的连接字符串用于队列触发

问题描述:

我在Visual Studio中具有Azure功能:

I have an Azure function in Visual Studio:

    [FunctionName("MyQueueProcessor")]
    [StorageAccount("StorageConnectionString")]
    public static async Task ProcessQueueMessage([QueueTrigger("my-queue")] string message, TextWriter log)
    {
        logInfo("Start processing message", LogLevel.TRACE, message, log);
    }

我在云的应用程序设置"中设置了StorageConnectionString,并且当我将功能从Visual Studio上传到Azure应用程序时,该功能最初运行时没有问题.

I have StorageConnectionString set in the Application Settings in the cloud, and when I upload the function from Visual Studio to an Azure App, the function initially runs without issues.

问题在于该功能应用频繁重启,有时在重启时该功能无法运行.通过查看Application Insights,我得到以下错误:

The problem is that the function app restarts frequently, and sometimes when it restarts, the function doesn't run. From looking at Application Insights, I get the following error:

以下2个函数有错误:ProcessQueueMessage: Microsoft.Azure.WebJobs.Host:错误索引方法 "MyQueueTrigger.ProcessQueueMessage". Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK'StorageConnectionString'连接 字符串丢失或为空. Microsoft Azure存储帐户 可以通过以下方式设置连接字符串:1.设置 连接字符串中名为"StorageConnectionString"的连接字符串 .config文件的connectionStrings部分采用以下格式 或2.设置名为的环境变量 'StorageConnectionString',或3.设置以下项的相应属性 JobHostConfiguration.运行:Microsoft.Azure.WebJobs.Host:错误 索引方法"MyTimerTrigger.Run". Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK'StorageConnectionString'连接 字符串丢失或为空. Microsoft Azure存储帐户 可以通过以下方式设置连接字符串:1.设置 连接字符串中名为"StorageConnectionString"的连接字符串 .config文件的connectionStrings部分采用以下格式 或2.设置名为的环境变量 'StorageConnectionString',或3.设置以下项的相应属性 JobHostConfiguration.

The following 2 functions are in error: ProcessQueueMessage: Microsoft.Azure.WebJobs.Host: Error indexing method 'MyQueueTrigger.ProcessQueueMessage'. Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK 'StorageConnectionString' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways: 1. Set the connection string named 'StorageConnectionString' in the connectionStrings section of the .config file in the following format , or 2. Set the environment variable named 'StorageConnectionString', or 3. Set corresponding property of JobHostConfiguration. Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'MyTimerTrigger.Run'. Microsoft.Azure.WebJobs.Host: Microsoft Azure WebJobs SDK 'StorageConnectionString' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways: 1. Set the connection string named 'StorageConnectionString' in the connectionStrings section of the .config file in the following format , or 2. Set the environment variable named 'StorageConnectionString', or 3. Set corresponding property of JobHostConfiguration.

似乎有时重新启动功能应用程序时,对StorageConnectionString的绑定会失败.如何防止这成为问题?

It appears that sometimes when the function app restarts, the binding to StorageConnectionString fails. How can I prevent this from being an issue?

我将代码转换为在门户网站中使用函数编辑器.我不接受这个答案,因为我希望有人有更好的解决方案.

I converted the code to use the function editor in the portal. I’m not accepting this answer as I’m hopeful someone has a better solution.