I have a queue of messages that I would like to read. Consider the following code, based on a queue of 100 items:
queue.FetchAttributes();
var orderCount = queue.ApproximateMessageCount;
while(orderCount > 0)
{
var messages = queue.GetMessages(32,TimeSpan.FromMinutes(1));
if (messages != null)
{
foreach (var item in messages)
{
Order singleOrder = new JavaScriptSerializer().Deserialize<Order>(item.AsString);
PendingOrders.Add(singleOrder);
}
}
queue.FetchAttributes();
orderCount = (messages == null) ? 0 : queue.ApproximateMessageCount;
}
In this instance, 3 calls will be made to "queue.GetMessages()" to retrieve 96 messages, followed by a 4th call to get the remaining 4. The loop will then exit and the list of items returned. When I run this, it appears to be lifting the same items over and over i.e. not incrementing. I was under the impression when I read an item, it removed it from the queue temporarily? So each time I read a message, it gets temporarily removed from my queue - in this case for 1 minute. Have I missed a step? Note, I am not calling 'DeQueue' anywhere as I want the item to return to the queue after 1 minute.