Azure 函数存储帐户连接字符串

See*_*arp 5 c# azure azure-storage azure-storage-queues azure-functions

我有一个函数应用程序定义如下

[StorageAccount("DefaultEndpointsProtocol=...;AccountName=…;AccountKey=...")]
public static class Function1
{
    [FunctionName("Function1")]
    [return: Queue("lets-test-this-out")]
    public static async Task<string> Run([QueueTrigger("lets-test-this-in")] Guid  guid, TraceWriter log)
    {
        await Task.Delay(1000);
        log.Info($"C# Queue trigger function processed: {guid}");
        return Guid.NewGuid().ToString();
    }
}
Run Code Online (Sandbox Code Playgroud)

其中lets-test-this-inlets-test-this-out是带有连接字符串的存储帐户下的现有存储队列的名称"DefaultEndpointsProtocol=...;AccountName=…;AccountKey=..."(直接从访问键 - 连接字符串复制门户中的)。我发布时生成的 function.json 就像

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "queueTrigger",
      "queueName": "lets-test-this-in",
      "connection": "DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;",
      "name": "guid"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/FunctionAppTest.dll",
  "entryPoint": "FunctionAppTest.Function1.Run"
}
Run Code Online (Sandbox Code Playgroud)

唯一值得怀疑的是我没有看到[return: Queue("lets-test-this")]在那里被转化为任何价值。

无论如何,这是行不通的:

  • 当我尝试在门户中测试该功能时,我看到 Status: 202 Accepted,但输出窗格中没有记录任何内容。
  • 当我留言时 lets-test-this-in,它不会被接收。
  • 流媒体日志会说 [Info] Executing HTTP request,然后什么都没有。

有趣的是,如果我在删除后重新发布 [StorageAccount]属性那么我可以在门户中进行测试并在流日志中看到它仍在执行。

可能相关的是我local.settings.json就像

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
    }
}
Run Code Online (Sandbox Code Playgroud)

Mik*_*kov 1

StorageAccount属性接受放置连接字符串的应用程序设置的名称,而不是连接字符串本身。例如

[StorageAccount("AzureWebJobsStorage")]
Run Code Online (Sandbox Code Playgroud)

输出绑定未在生成中显示function.json- 这很令人困惑,但却是预料之中的。