4

So im sending an item off my ASP.NET Web API to a Azure Storage Queue and i'd like to provide some feedback to the user on the position of their item in the queue aswell as be able to update them on the position of their item if they come back or something similar.

Not that it has much to do with the question here but this is the method im using to place the item in the Queue

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigHelper.GetAzureStorage());
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

CloudQueue queue = queueClient.GetQueueReference("my-queue");
await queue.CreateIfNotExistsAsync();

var messageJson = JsonConvert.SerializeObject(item);
CloudQueueMessage cloudQueueMessage = new CloudQueueMessage(messageJson);

await queue.AddMessageAsync(cloudQueueMessage);

So i've poked around CloudQueueClient and CloudQueue but all I could find was CloudQueue.ApproximateMessageCount which always returned null.

I've also tried a bit of googling how that always comes up with Getting started guides, noting specifically around how i'd go about getting the size then position of the item in a queue, so is it even possible?

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Toxicable
  • 1,639
  • 2
  • 21
  • 29

1 Answers1

7

It's not possible to get the position of the item within the queue.

For the approximate message count, you must call FetchAttributes or FetchAttributesAsync before retrieving the value. This will populate ApproximateMessageCount with the actual value from the queue.

porges
  • 30,133
  • 4
  • 83
  • 114
  • Well that kinda sucks, but at least since every item in the queue takes the same time to process and actually knowing how `ApproximateMessageCount` works I can just estimate the time it'll take and return that to the user, Thanks heaps – Toxicable May 03 '16 at 08:25
  • @Toxicable: it's mostly due to the way distributed queues work - there's no guarantee on the ordering of the messages. It will be close to first-in-first-out, but might not be 100%, so you can't give a number that indicates the position as it's a bit fuzzy – porges May 03 '16 at 09:39
  • Ohh I see, that makes sense. I didn't know it was a distributed queue, that makes sense than, thanks for clearing that up – Toxicable May 03 '16 at 09:48
  • @Toxicable if getting message count helps checkout the answer here http://stackoverflow.com/questions/18283583/azure-service-bus-queue-count – TusharJ May 03 '16 at 16:53
  • @Toxicable note that service bus queues are completely different from storage queues – porges May 04 '16 at 20:37