简体   繁体   中英

Windows Azure queue GetMessage returns null

I have a Windows Azure queue of CloudQueue. I use queue.GetMessage to retrieve message from queue, but it returns null.

I initialize my queue as below:

var setting = CloudConfigurationManager.GetSetting("DataConnectionString");
var storageAccount = CloudStorageAccount.Parse(setting);
var queueClient = storageAccount.CreateCloudQueueClient();
var queue = queueClient.GetQueueReference(RoleEnvironment.GetConfigurationSettingValue("QueueName"));
queue.CreateIfNotExists();

After that I add CloudQueueMessage in that queue like this:

CloudQueueMessage msg = new CloudQueueMessage(content);      
queue.AddMessage(msg);

When I check Message count:

queue.FetchAttributes();
int? count = queue.ApproximateMessageCount;  //returns 1

I get that count equals to 1, but when I try to get message:

var retrievedMsg = queue.GetMessage();    // returns null

I have retrievedMsg is null .

I'm confused. I have no code in but this in this method. But everytime I have retrieved message is null.

Any ideas?

Another option for getting started is to start with code that definitely works and then we can work backwards. Install the latest Azure SDK (2.5) and it will install some quickstarts directly in VS. From VS select File / New / Project / Cloud / Azure Storage Queues. Then update the app.config file to point to your service account. Confirm that works. Then it is either your code or some other environmental issue (multiple readers, etc).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM