【问题标题】:Azure Functions: How do you use a POCO in a binding expression with Azure Storage Queue?Azure Functions:如何在 Azure 存储队列的绑定表达式中使用 POCO?
【发布时间】:2020-02-02 20:20:37
【问题描述】:

我定义了一个使用 Azure 存储队列触发器和 Blob 输入绑定的 Azure 函数。我有一个用于队列触发器的 POCO,但是如何在 blob 输入绑定中使用该 POCO 和绑定表达式?

建筑:

  1. Azure 函数 2.x
  2. 预编译的 C# 库 (.NET Core 2.1)

POCO:

public class ImageToProcess
{
    public int CompanyId { get; set; }
    public string FullImagePath { get; set; }
}

Azure 函数:

public static void Run(
    [QueueTrigger("profile-image-queue", Connection = "ProfileImageQueue")]ImageToProcess myQueueItem,
    [Blob("profileimages/{queueTrigger.FullImagePath}", FileAccess.Read, Connection = "ProfileImageBlobConnectionString")] Stream originalImage,
    ILogger log)
{
    log.LogInformation($"Started Processing profile image: myQueueItem");
}

队列消息:

{ 
    "CompanyId": 123,
    "FullImagePath": "CompanyA/profileImage-original.png" 
}

错误信息:

System.Private.CoreLib:执行函数时出现异常:ProfileImageUploaded。 Microsoft.Azure.WebJobs.Host:异常绑定参数“originalImage”。 Microsoft.Azure.WebJobs.Host:访问“FullImagePath”时出错:属性不存在。

用于创建此解决方案的资源

  1. http://dontcodetired.com/blog/post/Improving-Azure-Functions-Blob-Trigger-Performance-and-Reliability-Part-2-Processing-Delays-and-Missed-Blobs
  2. https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger
  3. https://docs.microsoft.com/en-us/sandbox/functions-recipes/queue-storage#azure-storage-queue-trigger-using-a-poco

其他可能的解决方案: 我看到的唯一其他选择是使用命令式绑定,但我很确定我可以使用声明式绑定。 https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#binding-at-runtime

【问题讨论】:

  • 在 url 地址的情况下使用以下:"profileimages/{FullImagePath}""{FullImagePath}"
  • @RomanKiss - 修复了它,但函数如何知道该属性来自“QueueTrigger”元数据而不是其他一些元数据属性? docs.microsoft.com/en-us/azure/azure-functions/…
  • @RomanKiss - 在考虑之后,我猜编译器假设您正在尝试引用 queueTrigger 元数据上的属性,因为您必须按名称引用其他元数据属性?无论哪种方式,如果您将答案添加到我的帖子中,我会接受。
  • 看看docs.microsoft.com/en-us/azure/azure-functions/…,它也是基于触发器元数据的,例如HttpTrigger 将涉及查询字符串、标题。等等,然后是 {query.myid}、{headers.myid} 等等。
  • @RomanKiss - 是的,“JSON 有效负载”下的此语句确认了您的答案“注意 Blob 输入绑定通过直接引用 BlobName 属性(“path”:“strings/ {BlobName}")" 谢谢!

标签: azure azure-functions azure-storage-queues azure-function-app


【解决方案1】:

在 Blob 绑定中使用以下内容:

"profileimages/{FullImagePath}" 

注意,如果FullImagePath代表一个url地址,那么:

"{FullImagePath}" 

【讨论】:

  • 这里是文档:JSON Payloads
  • 没有对我的应用程序进行任何更改,这种方法现在突然失败了。
猜你喜欢
  • 2018-08-02
  • 1970-01-01
  • 2017-10-29
  • 2020-04-03
  • 1970-01-01
  • 2021-05-06
  • 2017-10-06
  • 1970-01-01
  • 2021-11-02
相关资源
最近更新 更多