【问题标题】:Fail to bind azure queue storage with azure functions(scheduler trigger) in portal无法在门户中将 azure 队列存储与 azure 函数(调度程序触发器)绑定
【发布时间】:2019-02-27 05:12:18
【问题描述】:

我正在构建一个 Azure 函数应用来访问 Azure 队列存储(调度器触发器)、检索消息并使用 SendGrid 发送电子邮件。

我花了很多时间调试和爬取 StackOverFlow,但仍然收到相同的错误消息。

这是错误信息。

[错误] 执行函数时出现异常: Functions.ScheduledMailCSharpHobby。 mscorlib:出现异常 由调用的目标抛出。 Microsoft.WindowsAzure.Storage: 设置的格式必须为“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"
    }
  ]
}

【问题讨论】:

    标签: c# azure azure-functions azure-storage-queues


    【解决方案1】:

    问题是由这条线引起的。

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse("serverlessbdbxxxxxxx");
    

    要访问存储帐户连接字符串,您需要

    1. 将连接字符串存储在门户上功能应用的应用程序设置中。

    2. 使用 GetEnvironmentVariable() 获取连接字符串。

      CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StorageConnectionString"));
      

    【讨论】:

    • 您好杰瑞,谢谢您的回复。问题解决了!!感谢您的善意帮助。
    • @WinnieChen 不客气,你可以接受我的回答来结束你的问题。
    猜你喜欢
    • 2021-10-30
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    相关资源
    最近更新 更多