Azure函数:如何在带有Azure存储队列的绑定表达式中使用POCO?

时间:2019-10-04 13:24:11

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

我定义了一个Azure函数,该函数使用Azure存储队列触发器和Blob输入绑定。我有一个用于队列触发器的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; }
}

天蓝色功能

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:执行函数ProfileProfileUploaded时发生异常。 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

1 个答案:

答案 0 :(得分:1)

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

"profileimages/{FullImagePath}" 

请注意,如果 FullImagePath 表示网址,则:

"{FullImagePath}"