Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

c# - azure function binding causing multiple events fired

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:

enter image description here

enter image description here

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

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

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

This step was generating 2 BlobCreated events!

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...