Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get queue length / message count from Azure

I have a Use Case where I need to queue a select number of messages when the current queue length drops below a specified value. Since I'm running in Azure, I'm trying to use the RetrieveApproximateMessageCount() method to get the current message count. Everytime I call this I get an exception stating StorageClientException: The specified queue does not exist.. Here is a review of what I've done:

  1. Created the queue in the portal and have successfully queued messages to it.

  2. Created the storage account in the portal and it is in the Created/Online state

  3. Coded the query as follows (using http and https options):

    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;
    
  4. I've confirmed the name is cased correctly with not special characters, numbers, or spaces and the resulting queue Url appears as though its correct formed based on the API documentations (e.g. http://myaccount.queue.core.windows.net/myqueue)

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


EDIT

I've confirmed that using the MessageFactory I can create a QueueClient and then enqueue/dequeue messages successfully. When I use the CloudStorageAccount the queue is never present so the counts and GetMessage routines never work. I am guessing these are not the same thing??? Assuming, I'm correct, what I need is to measure the length of the Service Bus Queue. Is that possible?

like image 501
JoeGeeky Avatar asked Jun 20 '12 23:06

JoeGeeky


1 Answers

RetrieveApproximateMessageCount() has been deprecated

if you want to use ApproximateMessageCount to get result try this

CloudQueue q = queueClient.GetQueueReference(QUEUE_NAME);
q.FetchAttributes();
qCnt = q.ApproximateMessageCount;
like image 112
Naga Sailesh Avatar answered Oct 08 '22 04:10

Naga Sailesh