Azure Functions - 将队列触发器与托管标识一起使用

Azure Functions - use queue trigger with managed identity

我正在尝试将托管身份与 Azure Functions V3 和 QueueTrigger 结合使用。 函数代码定义如下:

 [Function("ProcessUserData")]
 public async Task ProcessUserData([QueueTrigger("%QueueSettings:UserDataQueue%", Connection = "QueueSettings:StorageAccount")] string queueItem, FunctionContext context)
 {
      var logger = context.GetLogger<QueueListener>();
      ... 
 }

根据 Microsoft 文档,这应该可以通过定义一些额外的配置属性来实现

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference?tabs=blob#local-development-with-identity-based-connections

我的 local.settings.json 看起来像这样:

// "QueueSettings:StorageAccount": "",
"QueueSettings:StorageAccount__queueServiceUri": "https://mytestfa.queue.core.windows.net/",
"QueueSettings:StorageAccount__credential": "managedidentity",

尝试在本地 运行 项目时出现以下错误:

[2021-12-06T18:07:53.181Z] 'ProcessUserData' 函数出错:Microsoft.Azure.WebJobs.Host: 错误索引方法 'Functions.ProcessUserData'。 Microsoft.Azure.WebJobs.Extensions.Storage: 存储帐户连接字符串 'AzureWebJobsQueueSettings:StorageAccount' 不存在。确保它是已定义的应用程序设置。

当我使用并清空连接字符串时,出现另一个错误:

"QueueSettings:StorageAccount": "",
"QueueSettings:StorageAccount__queueServiceUri": "https://mytestfa.queue.core.windows.net/",
"QueueSettings:StorageAccount__credential": "managedidentity",

错误:

[2021-12-06T18:25:20.262Z] 'ProcessUserData'函数出错:Microsoft.Azure.WebJobs.Host: 错误索引方法'Functions.ProcessUserData'。 Microsoft.Azure.WebJobs.Extensions.Storage:'AzureWebJobsQueueSettings:StorageAccount' 的存储帐户连接字符串无效。

这在使用带有帐户密钥的完整连接字符串时工作正常,但我们必须使用托管身份。 我已经升级到最新版本的 Azure Functions Core Tole (3.0.3904) 并且正在使用 Visual Studio 2022.

应该 工作的其他文档: https://devblogs.microsoft.com/azure-sdk/introducing-the-new-azure-function-extension-libraries-beta/

感谢您的任何见解。

我可以通过安装 5.0.0-beta.4 版本的 NuGet 包“Microsoft.Azure.Functions.Worker.Extensions.Storage”来解决这个问题。

现在托管识别功能按预期工作。 希望这会很快进入 GA。