I have created a triggered web job using the Azure queue. For brevity, my function looks like this:
public static void ProcessQueueMessage([QueueTrigger("myqueue")] string message, TextWriter log)
{
log.WriteLine(message);
System.Threading.Thread.Sleep(10000);
}
I have another function that adds items to the queue for processing. However, I want to check the last xx
messages to determine if an item already exists in the queue (with the same message). Something like this:
while (true)
{
var myMessageId = "98uasd98fusad8";
CloudQueue queue = queueClient.GetQueueReference("myqueue");
queue.CreateIfNotExists();
var maxMessagesToCheck = 99;
var oldMessages = queue.GetMessages(maxMessagesToCheck, null);
if (!oldMessages.Any(x => x.AsString == myMessageId))
{
CloudQueueMessage message = new CloudQueueMessage(myMessageId);
queue.AddMessage(message);
}
}
However, I'm just not sure when an item is "popped" off the queue. Does it get popped off after processing is complete and the ProcessQueueMessage
function returns (without error)? Or, does it get popped off right as the processing starts?
If the items are popped off after the processing completes, then my second function above will work fine. However, if items are popped off as soon as the process starts, then I will have to find another solution.
This might be a more concise way of asking the question:
public static void ProcessQueueMessage([QueueTrigger("myqueue")] string message, TextWriter log)
{
//IS THE ITEM IN THE QUEUE POPPED OFF HERE?
log.WriteLine(message);
System.Threading.Thread.Sleep(10000);
} //OR IS THE ITEM IN THE QUEUE POPPED OFF HERE?