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?
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With