为什么我们会为同一个BlobCreated获得重复事件?
我在函数应用程序中使用以下绑定:
[Blob("%Detach:Output%/{file}", Write)] CloudBlockBlob @out,
我写此输出绑定的唯一时间是:
await @out.UploadTextAsync(xml);
我有一个这样定义的事件:
其中Detach:Output
的环境变量是xml-output-with-links-container
。
每次执行此功能,我始终会收到2个事件:
两个事件之间的eventTime
略有不同:
我们知道他们针对同一Blob触发,因为事件的subject
标识了它是哪个Blob:
"subject": "/blobServices/default/containers/xml-output-with-links-container/blobs/tobossthe_awesome_blob.xml",
我已经通过将有效负载上传到xml-output-with-links-container
进行了手动测试,并且仅触发了 1个事件。。但是,执行该函数时,会创建两个事件。
我们为什么会收到重复的事件?
这是整个功能:
{
[FunctionName("Detach")]
[StorageAccount("Global:Connection")]
public static async Task Run(
[QueueTrigger("%Detach:Trigger%")] DetachJob detach,
[Blob("%Detach:Input%/{file}", Read)] CloudBlockBlob @in,
[Blob("%Detach:Output%/{file}", Write)] CloudBlockBlob @out,
[Blob("%Detach:Error%/{file}", Write)] CloudBlockBlob fail,
[Blob("%Detach:Error%/{file}_error", Write)] CloudBlockBlob error,
[Blob("%Detach:Attachments%", Write)] CloudBlobContainer attachments)
{
try
{
var xml = await @in.DownloadTextAsync();
var size = ToInt32(GetEnvironmentVariable("Detach:BytesThreshold"));
var bigNodes = GetNodesGreaterThan(size, xml);
foreach (var node in bigNodes)
{
var ext = GetExtension(node.Value);
var path = $"{detach.file}/{node.Key}{ext}.base64";
var attachment = attachments.GetBlockBlobReference(path);
await attachment.UploadTextAsync(node.Value);
xml = xml.Replace(node.Value, path);
}
await @out.UploadTextAsync(xml);
}
catch (Exception e)
{
await error.UploadTextAsync(e.ToString());
await fail.StartCopyAsync(@in);
}
}
}
我当时在想CloudBlockBlob
可能触发了两次。所以我将绑定更改为CloudBlobContainer
:
[Blob("%Detach:Output%", Write)] CloudBlobContainer @out,
并更新了相应的代码:
var shrink = @out.GetBlockBlobReference(file);
await shrink.UploadTextAsync(xml);
但是结果保持不变:我仍然有2个事件。