无法在门户中将 azure 队列存储与 azure 函数(调度程序触发器)绑定
Fail to bind azure queue storage with azure functions(scheduler trigger) in portal
我正在构建一个 Azure 函数应用程序来访问 Azure 队列存储(调度程序触发器)、检索消息以及使用 SendGrid 发送电子邮件。
我花了很多时间调试和爬取 Whosebug,但仍然收到相同的错误消息。
这是错误信息。
[Error] Exception while executing function:
Functions.ScheduledMailCSharpHobby. mscorlib: Exception has been
thrown by the target of an invocation. Microsoft.WindowsAzure.Storage:
Settings must be of the form "name=value".
文件:run.csx
#r "SendGrid"
#r "Microsoft.WindowsAzure.Storage"
using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
public static Mail Run(TimerInfo myTimer, TraceWriter log)
{
var today = DateTime.Today.ToShortDateString();
log.Info($"Generating daily report for {today} at {DateTime.Now}");
Mail message = new Mail()
{
Subject = $"Daily Report for {today}"
};
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
// Get queue... create if does not exist.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("memberqueue");
// Peek at the next message
CloudQueueMessage peekedMessage = queue.PeekMessage();
// Display message.
log.Info(peekedMessage.AsString);
var mail_content = peekedMessage.AsString;
Content content = new Content
{
Type = "text/plain",
Value = $"Hi! {mail_content}"
};
message.AddContent(content);
return message;
}
文件:function.json
{
"bindings": [
{
"type": "timerTrigger",
"name": "myTimer",
"schedule": "0 0 17 * * *",
"direction": "in"
},
{
"type": "sendGrid",
"name": "$return",
"direction": "out",
"apiKey": "AzureWebJobsSendGridApiKey",
"from": "Azure Functions <samples@functions.com>",
"to": "xxxx@gmail.com"
}
]
}
问题是由这行引起的。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
要访问存储帐户连接字符串,您需要
将连接字符串存储在门户上函数应用程序的应用程序设置中。
使用 GetEnvironmentVariable() 获取连接字符串。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StorageConnectionString"));
我正在构建一个 Azure 函数应用程序来访问 Azure 队列存储(调度程序触发器)、检索消息以及使用 SendGrid 发送电子邮件。
我花了很多时间调试和爬取 Whosebug,但仍然收到相同的错误消息。
这是错误信息。
[Error] Exception while executing function: Functions.ScheduledMailCSharpHobby. mscorlib: Exception has been thrown by the target of an invocation. Microsoft.WindowsAzure.Storage: Settings must be of the form "name=value".
文件:run.csx
#r "SendGrid"
#r "Microsoft.WindowsAzure.Storage"
using System;
using SendGrid.Helpers.Mail;
using Microsoft.Azure;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
public static Mail Run(TimerInfo myTimer, TraceWriter log)
{
var today = DateTime.Today.ToShortDateString();
log.Info($"Generating daily report for {today} at {DateTime.Now}");
Mail message = new Mail()
{
Subject = $"Daily Report for {today}"
};
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
// Get queue... create if does not exist.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("memberqueue");
// Peek at the next message
CloudQueueMessage peekedMessage = queue.PeekMessage();
// Display message.
log.Info(peekedMessage.AsString);
var mail_content = peekedMessage.AsString;
Content content = new Content
{
Type = "text/plain",
Value = $"Hi! {mail_content}"
};
message.AddContent(content);
return message;
}
文件:function.json
{
"bindings": [
{
"type": "timerTrigger",
"name": "myTimer",
"schedule": "0 0 17 * * *",
"direction": "in"
},
{
"type": "sendGrid",
"name": "$return",
"direction": "out",
"apiKey": "AzureWebJobsSendGridApiKey",
"from": "Azure Functions <samples@functions.com>",
"to": "xxxx@gmail.com"
}
]
}
问题是由这行引起的。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
要访问存储帐户连接字符串,您需要
将连接字符串存储在门户上函数应用程序的应用程序设置中。
使用 GetEnvironmentVariable() 获取连接字符串。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StorageConnectionString"));