Azure Functions:如何在 Azure 存储队列的绑定表达式中使用 POCO?
Azure Functions: How do you use a POCO in a binding expression with Azure Storage Queue?
我定义了一个使用 Azure 存储队列触发器和 Blob 输入绑定的 Azure 函数。我有一个用于队列触发器的 POCO,但如何在 blob 输入绑定中使用该 POCO 和绑定表达式?
架构:
- Azure 函数 2.x
- 预编译的 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: Exception while executing function: ProfileImageUploaded. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'originalImage'. Microsoft.Azure.WebJobs.Host: Error while accessing 'FullImagePath': property doesn't exist.
用于创建此解决方案的资源
- http://dontcodetired.com/blog/post/Improving-Azure-Functions-Blob-Trigger-Performance-and-Reliability-Part-2-Processing-Delays-and-Missed-Blobs
- https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger
- 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
在 Blob 绑定中使用以下内容:
"profileimages/{FullImagePath}"
注意,如果 FullImagePath 表示 url 地址,则:
"{FullImagePath}"
我定义了一个使用 Azure 存储队列触发器和 Blob 输入绑定的 Azure 函数。我有一个用于队列触发器的 POCO,但如何在 blob 输入绑定中使用该 POCO 和绑定表达式?
架构:
- Azure 函数 2.x
- 预编译的 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: Exception while executing function: ProfileImageUploaded. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'originalImage'. Microsoft.Azure.WebJobs.Host: Error while accessing 'FullImagePath': property doesn't exist.
用于创建此解决方案的资源
- http://dontcodetired.com/blog/post/Improving-Azure-Functions-Blob-Trigger-Performance-and-Reliability-Part-2-Processing-Delays-and-Missed-Blobs
- https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger
- 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
在 Blob 绑定中使用以下内容:
"profileimages/{FullImagePath}"
注意,如果 FullImagePath 表示 url 地址,则:
"{FullImagePath}"