Azure函数: How do you use a POCO in a binding expression with Azure Storage Queue?

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

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

建筑:

  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: 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.

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

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

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

最佳答案

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

"profileimages/{FullImagePath}" 

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

"{FullImagePath}" 

关于Azure函数: How do you use a POCO in a binding expression with Azure Storage Queue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58237339/

相关文章:

sql-server - SSIS 连接管理器 - Azure SQL 数据库间歇性故障

c# - 我可以在 Azure DevOps 中使用 dotnetpublish 命令发布 .net Framework 4.7.1 解决方案吗

azure - 如何在Azure存储队列的开头插入消息?

Azure 存储队列和最多一次交付

python - 从 Python 添加项目到 Azure 存储队列时出错

c# - 动态对象,可持久保存到 Azure 并可通过 Dynamic Linq 进行查询

c# - Azure 网站添加子域

azure - 通过分析 Azure 日志发送警报

azure - 将根域指向 Azure Function

每个函数或全局的 Azure Functions host.json 设置?