0

I have this simple code:

      public void addMessage(string msg, string queueName)
    {
        CloudQueueMessage message = new CloudQueueMessage(msg);
        try {
           CloudQueue queue = getQueue(queueName);
           bool exists = queue.Exists();
           queue.AddMessage(message);
        }
        catch (Exception e) {
            e.ToString();
        }

    }

   public CloudQueue getQueue(string queueName)
             {
                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                CloudQueue queue = queueClient.GetQueueReference(queueName);
                queue.CreateIfNotExists();
                return queue;
            }

The message is set correctly, the queue name is correct, the queue exists but after call queue.AddMessage(message) the queue is still empty and no Exception is thrown. How is possible? With Blob and Table everything works fine (insert, delete, etc). I really cannot explain this.

Fabrizio Morello
  • 335
  • 1
  • 5
  • 18
  • Can you please explain why do you say "queue is still empty"? How are you checking the existence of messages in the queue? – Gaurav Mantri May 19 '16 at 15:05
  • From Visual Studio (Server Explorer) and from Azure Storage Explorer. Moreover, I placed a breakpoint on Worker Role when pop (from the Queue) a message that is not null. The Debugger never reachs this breakpoint, another proof that anything is added in the queue. – Fabrizio Morello May 19 '16 at 15:18
  • I also noticed that you are eating any exceptions that occur in your `addMessage` method. Could it be possible that your code is throwing an exception but you never come to know about it? – Gaurav Mantri May 19 '16 at 15:50
  • I use Debug to see if some exception is thrown, and everything goes "fine", in the sense that the method ends correctly. – Fabrizio Morello May 19 '16 at 16:11
  • 1
    Hmmm....totally weird! Your code looks OK to me (it can be optimized but that's another thing). Can you try adding following two lines of code after `queue.AddMessage(message);`: `queue.FetchAttributes(); int? messagesCount = queue.ApproximateMessageCount;`. Please check the value of `messagesCount` variable. If the message is inserted properly, you should see a non-null, non-zero value there. Also it wouldn't hurt to check the queue contents in a different storage explorer. – Gaurav Mantri May 19 '16 at 16:17

0 Answers0