Sam
Sam

Reputation: 30388

ProcessQueueMessage function in WebJob console app

I'm creating a new console app that I will run as a WebJob on Azure. When I created the new app in Visual Studio, it already created a Function.cs class that contains the following method which automatically picks up the message from my queue and processes it.

public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
   log.WriteLine(message);
}

My question is how do I have a bit more control over handling the queue message. For example, I 'd like to make sure the message is processed and deleted. This method seems to do all of that for me but how do I know if the message is processed correctly? What if it fails, how do I tell it not to delete the message?

Upvotes: 1

Views: 2947

Answers (1)

mathewc
mathewc

Reputation: 13558

Yes, all of that is handled for you. The queue message is only deleted if your function completes successfully. Until then, while your function is running the queue message is kept invisible so nobody else picks it up for processing. If your function fails, the message will become visible in a short period of time so it can be processed. If the queue message fails processing a configurable number of times (default is 5) the message is moved to a poison queue.

If you have advanced requirements and need to plug in deeply to the SDK queue processing pipeline, you can implement and register your own custom QueueProcessor instances to override/customize various parts of message processing. See this sample for more details.

Upvotes: 3

Related Questions