监视 Azure Blob 存储中的容器是否发生更改的最佳方法是什么?

发布于 2024-12-27 09:25:43 字数 119 浏览 2 评论 0原文

我正在寻找监视 Azure blob 存储中的容器/文件夹更改的最佳方法。到目前为止,我只找到了一种方法来做到这一点,那就是在某个地方运行一个工作进程,定期 ping 容器的内容以查找更改。

有更好的办法吗?

I am looking for the best way to monitor a container/folder in Azure blob storage for changes. So far I have only found one way to do this, which is to run a worker process somewhere that pings the container's contents on a regular basis to look for changes.

Is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

青丝拂面 2025-01-03 09:25:43

Storage SDK 不提供此功能,但它是新 WebJobs SDK 中的主要功能。有一个 [BlobInput] 属性,可让您指定要侦听的容器,并且它包含一个高效的 blob 侦听器,当检测到新的 blob 时,该侦听器将分派到该方法。有一些 blob 监听的示例:http://blogs.msdn.com/ b/jmstall/archive/2014/02/18/azure-storage-bindings-part-1-blobs.aspx

这是一个示例用法:

    public static void CopyWithStream(
        [BlobInput("container/in/{name}")] Stream input,
        [BlobOutput("container/out1/{name}")] Stream output
        )
    {
        Debug.Assert(input.CanRead && !input.CanWrite);
        Debug.Assert(!output.CanRead && output.CanWrite);

        input.CopyTo(output);
    }

以及 blob 侦听器位于此处:

        JobHost host = new JobHost(acs); // From nuget: Microsoft.WindowsAzure.Jobs.Host
        host.RunAndBlock();  

The Storage SDK doesn't provide this, but it is a primary feature in the new WebJobs SDK. There's a [BlobInput] attribute that lets you specify a container to listen on, and it includes an efficient blob listener that will dispatch to the method when new blobs are detected. There are some examples of blob listening at: http://blogs.msdn.com/b/jmstall/archive/2014/02/18/azure-storage-bindings-part-1-blobs.aspx

Here's an example usage:

    public static void CopyWithStream(
        [BlobInput("container/in/{name}")] Stream input,
        [BlobOutput("container/out1/{name}")] Stream output
        )
    {
        Debug.Assert(input.CanRead && !input.CanWrite);
        Debug.Assert(!output.CanRead && output.CanWrite);

        input.CopyTo(output);
    }

And the blob listener is under here:

        JobHost host = new JobHost(acs); // From nuget: Microsoft.WindowsAzure.Jobs.Host
        host.RunAndBlock();  
深居我梦 2025-01-03 09:25:43

正如其他人所说,以合理的时间间隔对您的应用程序进行轮询是可以的。但您不需要检查内容本身。您可以检查 ETag(如果使用纯 HTTP),也可以检查 BlobProperties.LastModifiedUtc(如果您使用的是 API)。

As others said, polling in a reasonable interval for your application is OK. But you don't need to check the content itself. You can check ETag (if using plain HTTP) or you can check BlobProperties.LastModifiedUtc if you're using API.

世俗缘 2025-01-03 09:25:43

恕我直言,没有更好的方法了。对不起。华泰

There is no better way, IMHO. Sorry. HTH

原谅我要高飞 2025-01-03 09:25:43

伊戈尔是对的,因为你需要轮询容器。我只是想澄清一些事情。当你说:

在某个地方运行一个工作进程,定期 ping 容器的内容以查找更改

工作进程可能是 Web 角色或工作角色、Run() 循环等中的线程。它不需要单独的角色。只需确保您的轮询代码适用于多个角色实例(例如,您可能希望将某种类型的页面 blob 租赁作为互斥锁,以确保您仅从一个实例进行轮询)。您还可以通过 Azure 队列执行此操作,因为队列消息现在支持消息创建时的不可见超时。

Igor's right, in that you'll need to poll the container. I just wanted to clarify something. When you said:

run a worker process somewhere that pings the container's contents on a regular basis to look for changes

The worker process may be a thread in a Web Role or Worker Role, the Run() loop, etc. It doesn't require a separate role. Just make sure your polling code works with multiple role instances (e.g. you may want to do some type of page blob lease as a mutex, to make sure you're polling from only one instance). You can also do this via Azure Queues, since queue messages now support an invisibility timeout upon message-creation.

软糖 2025-01-03 09:25:43

假设您可以控制更新/更改 blob 的代码,则可以使用 SignalR 在 blob 更改时生成推送通知,从而避免重复轮询的需要。

Assuming you have control over the code that updates/changes the blob, you can use SignalR to generate a push notification whenever the blob changes thereby avoiding the need for repeated polling.

柠檬心 2025-01-03 09:25:43

Azure 存储分析是否包含所需的信息?您仍然需要一些东西来进行投票。

Do the azure storage analytics hold the required information? You would still need something to do the polling.

眼泪也成诗 2025-01-03 09:25:43

老问题,但我正在研究这个主题,发现您现在可以使用 Azure 事件网格(不要与 Azure 事件中心混淆)在 Blob 存储发生更改时收到通知:

https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-event-overview

Old issue but I was researching this topic and found that you can now use Azure Event Grid (not to be confused with Azure Event Hubs) to get notified when changes in blob storage occurs:

https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-event-overview

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文