Skip to content

Instantly share code, notes, and snippets.

@vkurpad
Last active January 7, 2017 21:11
Show Gist options
  • Save vkurpad/e82f9498723bcd5b21793db5bfea9c36 to your computer and use it in GitHub Desktop.
Save vkurpad/e82f9498723bcd5b21793db5bfea9c36 to your computer and use it in GitHub Desktop.
Azure Functions Execution Errors and Poison Queues in Azure Storage
Recently I was asked the question on how to be notified when your Azure Function pushes a message into a poison queue as a result of execution errors. My approach to the problem is a little different and I thought I'd share it here. If you've got an alternate solution, please do share and lets keep the conversation going.
In general rather than rely on the Azure Functions runtime to write the message to a poison queue, I'm checking the dequeue count of the message and at the 5th attempt, I'm ensurig a successful completion by just writing the message out to a queue I use for exception processing. The documentation (https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage) has more information on the dequeueCount and other attributes. Aagin this is not a substitute for a Try-Catch but just an additional precaution.
Here's an example C# Azure Function where I simply try to convert the message content to an int with no exception handling, if the message is a string, I'll endup with the dequeueCount of 5 in the if block to execute whatever my excpetion handling process is.
using System;
public static void Run(string myQueueItem, TraceWriter log, int dequeueCount)
{
if(dequeueCount == 5)
{
//Process my logic here to avoid writing the mesage to a posion queue
//Return a successful execution
return;
}
log.Info($"C# Queue trigger function processed: {myQueueItem}");
log.Info($"dequeueCount={dequeueCount}");
int numVal = Convert.ToInt32(myQueueItem);
log.Info($"NumVal = {numVal}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment