Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to monitor a container in Azure blob storage for changes?

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?

like image 699
Bill Forney Avatar asked Jan 17 '12 04:01

Bill Forney


2 Answers

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();  
like image 130
Mike S Avatar answered Sep 27 '22 18:09

Mike S


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.

like image 39
cincura.net Avatar answered Sep 27 '22 17:09

cincura.net