azure function binding causing multiple events fired

眉间皱痕 提交于 2019-12-13 08:07:32

问题


Why are we getting duplicate events for the same BlobCreated?

I'm using the following binding in my function app:

        [Blob("%Detach:Output%/{file}", Write)] CloudBlockBlob @out,

The only time when I am writing to this output binding is here:

            await @out.UploadTextAsync(xml);

I have an event defined like so:

Where Detach:Output env variable is xml-output-with-links-container.

I am consistently getting 2 events for every execution of this function:

The eventTime between the two events are slightly different:

  • 2019-08-05T22:27:06.5279893Z
  • 2019-08-05T22:27:06.5019647Z

We know that they are firing for the same blob because the subject of the event identifies which blob it is:

"subject": "/blobServices/default/containers/xml-output-with-links-container/blobs/tobossthe_awesome_blob.xml",

I've tested this manually by uploading a payload to xml-output-with-links-container and have gotten just 1 event to fire. Yet, when the function is executed, two events are created.

Why are we getting duplicate events?

Here's the entire function:

{
        [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);
            }
        }
    }

I was thinking that perhaps the CloudBlockBlob was triggering twice. So I changed the binding to be CloudBlobContainer:

        [Blob("%Detach:Output%", Write)] CloudBlobContainer @out,

And updated the respective code:

            var shrink = @out.GetBlockBlobReference(file);
            await shrink.UploadTextAsync(xml);

Yet the result stayed the same: I still got 2 events.


回答1:


I was triggering the Detach function by dropping a payload into blob storage using a logic app with the following step:

This step was generating 2 BlobCreated events!

After turning off thunking, the issue has been resolved, and only 1 BlobCreated event is now generating:



来源:https://stackoverflow.com/questions/57380280/azure-function-binding-causing-multiple-events-fired

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