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.

Mark C.
  • 6,332
  • 4
  • 35
  • 71
  • 1
    Really good question, that's something I've been looking to find out as well. I'm doing some digging now :) – Martyn C May 18 '16 at 18:27

1 Answers1

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.

  • 1
    Very interesting..Thanks for the heads up. Any particular reason that the call for `FetchAttributes` is necessary? Assuming it was an architecture decision? – Mark C. May 19 '16 at 12:05
  • 6
    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. – Michael Roberson - MSFT May 30 '16 at 06:55
  • FetchAttributes does not always populate ApproimateMessageCount - i am still getting null. I have resorted to PeekMessage – OzBob Jan 14 '21 at 04:53
  • @OzBob, how PeekMessage helps to return MessageCount? Are you looping through all of messages? What it there are millions of them? – Michael Freidgeim Jun 23 '22 at 01:28