简体   繁体   English

Windows Azure队列GetMessage返回null

[英]Windows Azure queue GetMessage returns null

I have a Windows Azure queue of CloudQueue. 我有一个Windows Azure队列CloudQueue。 I use queue.GetMessage to retrieve message from queue, but it returns null. 我使用queue.GetMessage从队列中检索消息,但它返回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添加到该队列中,如下所示:

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: 我得到的计数等于1,但是当我尝试获取消息时:

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

I have retrievedMsg is null . 我已retrievedMsgnull

I'm confused. 我糊涂了。 I have no code in but this in this method. 我没有代码,但是用这种方法。 But everytime I have retrieved message is null. 但是,每次我检索到的消息都是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. 安装最新的Azure SDK(2.5),它将直接在VS中安装一些快速入门。 From VS select File / New / Project / Cloud / Azure Storage Queues. 从VS中选择“文件” /“新建” /“项目” /“云” /“ Azure存储队列”。 Then update the app.config file to point to your service account. 然后更新app.config文件以指向您的服务帐户。 Confirm that works. 确认有效。 Then it is either your code or some other environmental issue (multiple readers, etc). 然后是您的代码或其他环境问题(多个读者等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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