天蓝色函数绑定导致触发多个事件 [英] azure function binding causing multiple events fired

查看:80
本文介绍了天蓝色函数绑定导致触发多个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们会为相同的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:

其中Detach:Output env变量为xml-output-with-links-container的地方.

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

每次执行此功能,我始终会收到2个事件:

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

两个事件之间的eventTime略有不同:

The eventTime between the two events are slightly different:

  • 2019-08-05T22:27:06. 5279893Z
  • 2019-08-05T22:27:06. 5019647Z
  • 2019-08-05T22:27:06.5279893Z
  • 2019-08-05T22:27:06.5019647Z

我们知道它们针对同一Blob触发,因为事件的subject标识了该Blob:

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",

我已经通过将有效负载上传到xml-output-with-links-container进行了手动测试,并且仅触发了 1个事件..但是,执行该函数时,会创建两个事件.

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.

我们为什么要重复活动?

这是整个功能:

{
        [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:

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

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

并更新了相应的代码:

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

但是结果保持不变:我仍然有2个事件.

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

推荐答案

我通过使用逻辑应用程序通过以下步骤将有效负载放入blob存储中来触发Detach函数:

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

此步骤正在生成2个BlobCreated事件!

关闭thunking后,问题已解决,并且现在仅生成1个BlobCreated事件:

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

这篇关于天蓝色函数绑定导致触发多个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆