Azure 函数存储帐户连接字符串
Azure Function storage account connection string
我有一个定义为
的函数应用程序
[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-in
和 lets-test-this-out
是具有连接字符串 "DefaultEndpointsProtocol=...;AccountName=…;AccountKey=..."
的存储帐户下现有存储队列的名称(直接从 Access keys - Connection string 复制 在门户中)。我发布时生成的 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"
}
}
StorageAccount
属性接受放置连接字符串的应用程序设置名称,而不是连接字符串本身。例如
[StorageAccount("AzureWebJobsStorage")]
生成的 function.json
中未显示输出绑定 - 这令人困惑,但符合预期。
我有一个定义为
的函数应用程序[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-in
和 lets-test-this-out
是具有连接字符串 "DefaultEndpointsProtocol=...;AccountName=…;AccountKey=..."
的存储帐户下现有存储队列的名称(直接从 Access keys - Connection string 复制 在门户中)。我发布时生成的 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"
}
}
StorageAccount
属性接受放置连接字符串的应用程序设置名称,而不是连接字符串本身。例如
[StorageAccount("AzureWebJobsStorage")]
生成的 function.json
中未显示输出绑定 - 这令人困惑,但符合预期。