Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Azure Webjobs to the rescue

Azure Webjobs to the rescue

In this presentation we demo the options of using Azure Webjobs to offload computation intensive work from your website to background queues.

Mark van Straten

March 27, 2015
Tweet

More Decks by Mark van Straten

Other Decks in Programming

Transcript

  1. Azure Storage Queue Your web app var queueClient = Settings.GetWebjobStorageAccount.CreateCloudQueueClient();

    var queue = queueClient.GetQueueReference("sendEmailQueue"); queue.CreateIfNotExists(); await queue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject (new SendEmailQueueMessage { EmailTemplate = "succes", OrderId = 1234, Language = "nl" })));
  2. Azure Storage Queue Your Web Job private static void Main()

    { new JobHost().RunAndBlock(); } public async static Task SendEmail([QueueTrigger("sendEmailQueue")] SendEmailQueueMessage message, TextWriter logger) { logger.Write("Going to send email for order " + message.OrderId); }
  3. POISON QUEUE private static void Main() { new JobHost().RunAndBlock(); }

    public async static Task ProcessSendEmailPoisonMessage([QueueTrigger ("sendEmailQueue-poison")] SendEmailQueueMessage message, TextWriter logger) { logger.Write("Failed sending email for order " + message.OrderId); } Azure Storage Poison Queue Your Web Job
  4. Solution: suffix queue names with app-version to let swapped old

    version deplete its own queue. sendemails-1.2.3 → sendemails-1.2.4 Con: Manual old queues cleanup after a few deploys