将多个 Blob 输入传递给 QueueTrigger Azure 函数的最佳方式
Best Way to Pass Multiple Blob Inputs to a QueueTrigger Azure Function
问题
触发后,生成 3 个 XML 文件,完成后,ftp 将它们发送到站点。
当前方法
我有一个 HTTP 触发器 Azure 函数,当 运行 将构建 3 个 XML 文件并将它们保存到 Azure 存储 Blob 容器中。因为有多个输出,而且需要控制输出path/filenames,我用
imperative binding approach 并在我的函数中使用 IBinder outputBinder
。这一切都很好。 Blob 存储中的输出路径示例是 export/2017-03-22/file-2017-03-22T12.03.02.54.xml
。文件在一个带日期的文件夹中,每个文件名都有时间戳以确保唯一性。
生成所有 3 个文件后,我想触发另一个函数,将这些文件发送到站点 FTP。现在我最初认为我应该使用 blob 触发器,但我不知道如何触发文件名和路径是动态的输入。我在 blob trigger documentation.
中找不到这样的例子
然后我想我可以将我的 HTTP 触发器输出到声明性绑定,并将 XML 文件输出到我的 blob 存储中的 outgoing
容器中,我的 blob 触发器可以查看.这也有效,但是因为我的功能在消费计划上,所以最多可以有 10-minute day in processing new blobs.
因此记录的替代方法是使用队列触发器。我可以输出到我的队列并让队列触发器正常运行,但是我如何将 3 XML 流也传递到我的 QueueTrigger 函数?
我想作为后备,我可以 post 一个对象,它可以包含构建的 XMLs 的 Azure 存储路径,然后使用存储 SDK 获取流并使用它到 post 到 FTP,但是将这些 Storage Blob 流作为输入传递到我的 QueueTrigger 会更有效吗?
我认为您使用队列触发器的方法很有意义。我会构建这样的消息
public class QueueItem
{
public string FirstBlobPath { get; set; }
public string SecondBlobPath { get; set; }
public string ThirdBlobPath { get; set; }
}
然后在队列处理函数中使用声明式绑定,比如
{
"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)
{
}
问题
触发后,生成 3 个 XML 文件,完成后,ftp 将它们发送到站点。
当前方法
我有一个 HTTP 触发器 Azure 函数,当 运行 将构建 3 个 XML 文件并将它们保存到 Azure 存储 Blob 容器中。因为有多个输出,而且需要控制输出path/filenames,我用
imperative binding approach 并在我的函数中使用 IBinder outputBinder
。这一切都很好。 Blob 存储中的输出路径示例是 export/2017-03-22/file-2017-03-22T12.03.02.54.xml
。文件在一个带日期的文件夹中,每个文件名都有时间戳以确保唯一性。
生成所有 3 个文件后,我想触发另一个函数,将这些文件发送到站点 FTP。现在我最初认为我应该使用 blob 触发器,但我不知道如何触发文件名和路径是动态的输入。我在 blob trigger documentation.
中找不到这样的例子然后我想我可以将我的 HTTP 触发器输出到声明性绑定,并将 XML 文件输出到我的 blob 存储中的 outgoing
容器中,我的 blob 触发器可以查看.这也有效,但是因为我的功能在消费计划上,所以最多可以有 10-minute day in processing new blobs.
因此记录的替代方法是使用队列触发器。我可以输出到我的队列并让队列触发器正常运行,但是我如何将 3 XML 流也传递到我的 QueueTrigger 函数?
我想作为后备,我可以 post 一个对象,它可以包含构建的 XMLs 的 Azure 存储路径,然后使用存储 SDK 获取流并使用它到 post 到 FTP,但是将这些 Storage Blob 流作为输入传递到我的 QueueTrigger 会更有效吗?
我认为您使用队列触发器的方法很有意义。我会构建这样的消息
public class QueueItem
{
public string FirstBlobPath { get; set; }
public string SecondBlobPath { get; set; }
public string ThirdBlobPath { get; set; }
}
然后在队列处理函数中使用声明式绑定,比如
{
"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)
{
}