简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM