Best Way to Pass Multiple Blob Inputs to a QueueTrigger Azure Function

谁说胖子不能爱 提交于 2019-12-07 01:37:17

问题


The Problem

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

The Current Approach

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.

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.

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.

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?

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?


回答1:


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
}

and the function

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


来源:https://stackoverflow.com/questions/42991415/best-way-to-pass-multiple-blob-inputs-to-a-queuetrigger-azure-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!