Unable to get queue length / number of messages from Azure

I have a use case where I need to queue a selected number of messages when the current queue length falls below a specified value. Since I work in Azure, I am trying to use the RetrieveApproximateMessageCount() method to get the current number of messages. Each time I call it, I get an exception indicating StorageClientException: The specified queue does not exist. . Here is an overview of what I did:

  • Created a queue in the portal and successfully queued messages.

  • Created a vault account in the portal and is in the "Created / Online" state

  • Encoded the request as follows (using the http and https parameters):

     var storageAccount = new CloudStorageAccount( new StorageCredentialsAccountAndKey(_messagingConfiguration.StorageName.ToLower(), _messagingConfiguration.StorageKey), false); var queueClient = storageAccount.CreateCloudQueueClient(); var queue = queueClient.GetQueueReference(queueName.ToLower()); int messageCount; try { messageCount = queue.RetrieveApproximateMessageCount(); } catch (Exception) { //Booom!!!!! in every case } // ApproximateMessageCount is always null messageCount = queue.ApproximateMessageCount == null ? 0 : queue.ApproximateMessageCount.Value; 
  • I confirmed that the name is correctly circled not with special characters, numbers or spaces, and the resulting queue Url looks as if it were correctly formed based on the API documentation (for example, http://myaccount.queue.core.windows.net/myqueue )

Can someone help shed light on what I'm doing wrong.


EDIT

I confirmed that with MessageFactory I can create a QueueClient message and then send to the queue / deactivate the messages. When I use CloudStorageAccount , the queue does not exist, so the GetMessage counts and procedures never work. I assume this is not the same thing ??? Assuming I'm right, I need to measure the length of the service bus queue. Is it possible?

+4
source share
1 answer

RetrieveApproximateMessageCount () is deprecated

if you want to use ApproximateMessageCount to get the result, try

 CloudQueue q = queueClient.GetQueueReference(QUEUE_NAME); q.FetchAttributes(); qCnt = q.ApproximateMessageCount; 
+35
source

All Articles