@H_301_3@
我正在制作一个小应用程序,应该列出我的Azure队列中的项目数.
当我在Console App中使用FetchAttributesAsync和ApproximateMessageCount时,在调用FetchAttributesAsync(或FetchAttributes)之后,我在ApproximateMessageCount中得到了预期的结果.
当我在Console App中使用FetchAttributesAsync和ApproximateMessageCount时,在调用FetchAttributesAsync(或FetchAttributes)之后,我在ApproximateMessageCount中得到了预期的结果.
当我在通用Windows应用程序中使用相同内容时,在调用FetchAttributesAsync后,ApproximateMessageCount仍保持为null(FetchAttributes在那里不可用).
控制台代码:
CloudStorageAccount _account; if (CloudStorageAccount.TryParse(_connectionstring,out _account)) { var queueClient = _account.CreateCloudQueueClient(); Console.WriteLine(" {0}",_account.QueueEndpoint); Console.WriteLine(" ----------------------------------------------"); var queues = (await queueClient.ListQueuesSegmentedAsync(null)).Results; foreach (CloudQueue q in queues) { await q.FetchAttributesAsync(); Console.WriteLine($" {q.Name,-40} {q.ApproximateMessageCount,5}"); } }
通用应用代码:
IEnumerable<CloudQueue> queues; CloudStorageAccount _account; CloudQueueClient queueClient; CloudStorageAccount.TryParse(connectionstring,out _account); queueClient = _account.CreateCloudQueueClient(); queues = (await queueClient.ListQueuesSegmentedAsync(null)).Results; foreach (CloudQueue q in queues) { await q.FetchAttributesAsync(); var count = q.ApproximateMessageCount; // count is always null here!!! }
我尝试过各种各样的替代方案,比如Wait()等等等等等.无论我尝试什么,ApproximateMessageCount都保持为null并且具有dertermination :-(.
我错过了什么吗?
解决方法
我认为您在存储客户端库中发现了一个错误.我查找了Github上的代码,基本上没有读取近似消息计数标头的值,代码正在读取Lease Status标头的值.
在QueueHttpResponseParsers.cs
班:
public static string GetApproximateMessageCount(HttpResponseMessage response) { return response.Headers.GetHeaderSingleValueOrDefault(Constants.HeaderConstants.LeaseStatus); }
这个方法应该是:
public static string GetApproximateMessageCount(HttpResponseMessage response) { return response.Headers.GetHeaderSingleValueOrDefault(Constants.HeaderConstants.ApproximateMessagesCount); }
我已经提交了一个错误:https://github.com/Azure/azure-storage-net/issues/155.
@H_301_3@