Why is the ApproximateMessageCount property on an Azure Storage queue nullable?
Asked Answered
S

1

15

The title pretty much explains my question:

If there are no messages in the Storage Queue, why would it not just return 0, assuming we were able to get the queue reference and make a connection? Instead, it returns null.

Does it have to do with the fact that the message count is "approximate?" Curious, more than anything.

Scum answered 18/5, 2016 at 16:47 Comment(1)
Really good question, that's something I've been looking to find out as well. I'm doing some digging now :)Mcauliffe
D
17

The approximate message count starts as null to indicate that it has not been initialized. After the first call to FetchAttributes, it is populated with the current value from the service. If there are no messages in the queue at this point then the value returned is zero.

Derosa answered 19/5, 2016 at 7:50 Comment(4)
Very interesting..Thanks for the heads up. Any particular reason that the call for FetchAttributes is necessary? Assuming it was an architecture decision?Scum
We prefer the service calls to be explicit -- FetchAttributes sends a request on the wire and gets the queue metadata and approx. message count. We decided to avoid having such a (relatively) heavy operation on a property getter.Derosa
FetchAttributes does not always populate ApproimateMessageCount - i am still getting null. I have resorted to PeekMessageLeges
@OzBob, how PeekMessage helps to return MessageCount? Are you looping through all of messages? What it there are millions of them?Mignonmignonette

© 2022 - 2024 — McMap. All rights reserved.