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

5

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

[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();
    }
}

其中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"
}

关于这件事唯一可疑的是,我没有看到[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"
    }
}
1个回答

1

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

[StorageAccount("AzureWebJobsStorage")]

输出绑定不会显示在生成的function.json中 - 这很令人困惑,但是这是预期的。

实际上,参数文档中列出了三种可能性之一:- 可以是您选择的应用程序设置或连接字符串名称 - See Sharp
@SeeSharp Mikhail是正确的,请参考函数文档 - Jerry Liu
@SeeSharp 是的,而你的既不是应用程序设置名称,也不是连接“名称”。 - Mikhail Shilkov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接