将多个Blob输入传递到QueueTrigger Azure函数的最佳方法 [英] Best Way to Pass Multiple Blob Inputs to a QueueTrigger Azure Function

查看:169
本文介绍了将多个Blob输入传递到QueueTrigger Azure函数的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在触发器上,生成3个XML文件,完成后,将它们通过ftp下载到站点.

Upon a trigger, generate 3 XML files and once complete, ftp them to a site.

我有一个HTTP触发器Azure函数,该函数在运行时将构造3个XML文件并将其保存到Azure Storage Blob容器中.由于有多个输出,并且需要控制输出路径/文件名,因此我使用 命令式绑定方法,并在我的函数中使用IBinder outputBinder.这一切都很好. Blob存储中的输出路径示例是export/2017-03-22/file-2017-03-22T12.03.02.54.xml.该文件位于带有日期的文件夹中,每个文件名都带有时间戳以确保唯一性.

I have a HTTP Trigger Azure function that when run will construct 3 XML files and save these to an Azure Storage Blob container. Because of the multiple outputs, and the need to control the output path/filenames, I use the imperative binding approach and use the IBinder outputBinder in my function. This all works just fine. An example of the output path in the blob storage is export/2017-03-22/file-2017-03-22T12.03.02.54.xml. The file is in a folder with the date, and each filename has the time stamp to ensure uniqueness.

当生成所有3个文件时,我想触发另一个将这些文件sFTP传输到站点的功能.现在,我最初以为我应该使用Blob触发器,但是我不知道如何在文件名和路径是动态的输入上触发.我在 blob触发文档.

When all 3 files are generated, I want to trigger another function that will sFTP these to a site. Now I initially thought that I should use a blob trigger, but I couldn't figure how how to trigger on inputs that whose filenames and paths were dynamic. I coudldn't find such an example in the blob trigger documentation.

因此,我当时以为我可以将HTTP触发器输出输出到声明性绑定,并且还可以将XML文件输出到我的blob触发器可以查看的blob存储器中的outgoing容器中.但是,这也有效,因为我的功能在消耗计划上,因此最多可以有一个

So then I thought I could have my HTTP Trigger output to a declarative binding and also output the XML files into an outgoing container in my blob storage which my blob trigger could be looking at. This also works however because my function is on the consumption plan, there can be up to a 10-minute day in processing new blobs.

因此,记录在案的替代方法是使用队列触发器.我可以输出到队列并让队列触发正常,但是如何将3个XML流也传递给QueueTrigger函数呢?

So the documented alternative is to use a queue trigger. I can output to my queue and have the queue trigger just fine, but how do I also pass the 3 XML streams to my QueueTrigger function?

我想作为一个回退,我可以发布一个对象,该对象可以包含所构造的XML的Azure存储路径,然后使用Storage SDK来获取流并将其发布到FTP,但这会更多将这些Storage Blob流作为输入传递给QueueTrigger的效率很高?

I suppose as a fall back, I can post an object that can contain the Azure Storage paths of the constructed XMLs and then use the Storage SDK to fetch the streams and use that to post to the FTP, but would it be more efficient to also pass those Storage Blob streams as an input to my QueueTrigger?

推荐答案

我认为您使用Queue Trigger的方法很有意义.我会像这样构造一条消息

I think your approach with Queue Trigger makes sense. I would construct a message like this

public class QueueItem
{
    public string FirstBlobPath { get; set; }
    public string SecondBlobPath { get; set; }
    public string ThirdBlobPath { get; set; }
}

,然后在队列处理功能中使用声明性绑定,例如

and then use declarative binding in the queue processing function, something like

{
  "bindings": [
    {
      "type": "queueTrigger",
      "name": "item",
      "direction": "in",
      "queueName": "myqueue",
      "connection":"...",    
    },
    {
      "type": "blob",
      "name": "file1",
      "path": "mycontainer/{FirstBlobPath}",
      "connection": "...",
      "direction": "in"
    },
    {
      "type": "blob",
      "name": "file2",
      "path": "mycontainer/{SecondBlobPath}",
      "connection": "...",
      "direction": "in"
    },
    {
      "type": "blob",
      "name": "file3",
      "path": "mycontainer/{ThirdBlobPath}",
      "connection": "...",
      "direction": "in"
    }
  ],
  "disabled": false
}

和功能

public static void Run(QueueItem item, Stream file1, Stream file2, Stream file3)
{
}

这篇关于将多个Blob输入传递到QueueTrigger Azure函数的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆