2

I have a Azure Storage account with several containers. I am using BlobTrigger Function to detect new blobs.

Now this is seems working perfectly. But a BlobTrigger only works on one container. Seems like a bad idea to create one trigger pr container (I will duplicate a lot of code).

Is there any way to simplify this? Ideas are appreciated.

PS: I know that BlobTrigger is not reliable if there are 10K blobs or more in the container (but this is not my case).

1 Answer 1

1

Is there any way to simplify this? Ideas are appreciated.

An Azure Storage blob trigger only lets you monitor one storage container for new and updated blobs. If you want to monitor multi containers in a Azure Storage Account, you need to create multi functions.

I suggest you write the blob changed processing logic in one method and invoke this method when other functions are called.

public static void ProcessBlob(string containerName, string blobName, CloudBlockBlob blob)
{
    //Write your logic here
}

public static void ProcessBlobContainer1([BlobTrigger("container1/{blobName}")] CloudBlockBlob blob, string blobName)
{
    ProcessBlob("container1", blobName, blob);
}

public static void ProcessBlobContainer2([BlobTrigger("container2/{blobName}")] CloudBlockBlob blob, string blobName)
{
    ProcessBlob("container2", blobName, blob);
}

There is open issue on GitHub which related to your question, hoping that it will be solved soon.

Add ability to create blob triggers on a container names that match a pattern

Sign up to request clarification or add additional context in comments.

2 Comments

Do I need to implement this as an Azure WebJob? Cant seem to fit this into Azure Functions (as you set the container values in the bindings)
Yes, you could implement this as a WebJob, we could define multi functions in a WebJob.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.