onefootswill
onefootswill

Reputation: 4107

What's the Best Way to Write Text to Blob in an Azure Webjob

I have an Azure Webjob. It's dequeuing a message and processing it. When it dequeues the message it uses the default model binder to enable me to have a strong-typed parameter. At the moment, the signature to that function looks like this:

DequeueCUWebinarMessages([QueueTrigger("tts-cuw-notifications-queue")] NotificationMessage notificationMessage, int dequeueCount, TextWriter log)

I want to store one of the properties of that NotificationMessage object to blob storage. The property in question is a string (specifically, html).

I am aware of the fact that there are Blob attributes which you can use in your WebJobs functions. So my question is, should I use one of those blob attributes? And if so, what would my new function signature look like?

Or, should I just use the storage client API to "upload" the string to a blob container?

What would be the best practice?

Upvotes: 2

Views: 1130

Answers (1)

Victor Hurdugaci
Victor Hurdugaci

Reputation: 28425

You can use the WebJobs SDK to do that. Here is how the function could look like:

DequeueCUWebinarMessages(
    [QueueTrigger("tts-cuw-notifications-queue")] NotificationMessage notificationMessage, 
    [Blob("output/blob.txt")] out string blob,
    int dequeueCount, 
    TextWriter log)
{
     blob = "blob content";
}

Instead of string you can also use Stream, TextWriter, CloudBlockBlob, ICloudBlob or your own custom type if you implement a customer serializer.

Upvotes: 2

Related Questions