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:
Created the queue in the portal and have successfully queued messages to it.
Created the storage account in the portal and it is in the Created/Online state
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;
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?
queue.AddMessage(...)
orqueue.GetMessage(...)
? – Barkqueue.GetMessage()
right beforequeue.RetrieveApproximateMessageCount()
. I'm betting it fails with the same error. – BarkServices --> Service Bus --> Queues
in the portal I can see the Queue exists and has messages in it. When I use theMessagingFactory
I can create aQueueClient
and Enqueue/Dequeue with no problem, but can't see the length. When I use theCloudStorageAccount
and generate aCloudQueue
instance the queue does not exist. I'm guessing these are not the same queues? How can I get length of a Service Bus Queue? Have I just completely jumbled seperate tech? – Flute