Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Azure Storage Queue size/position

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?

like image 693
Toxicable Avatar asked Mar 12 '23 10:03

Toxicable


1 Answers

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.

like image 127
porges Avatar answered Mar 23 '23 09:03

porges