【问题标题】:ApproximateMessageCount always null after calling FetchAttributesAsync in a Universal windows App在通用 Windows 应用程序中调用 FetchAttributesAsync 后,ApproximateMessageCount 始终为空
【发布时间】:2015-08-03 22:09:27
【问题描述】:

我正在制作一个小应用程序,它应该列出我的 Azure 队列中的项目数。 当我在控制台应用程序中使用 FetchAttributesAsync 和 ApproximateMessageCount 时,在调用 FetchAttributesAsync(或 FetchAttributes)后,我在 ApproximateMessageCount 中得到了预期的结果。

当我在通用 Windows 应用程序中使用它时,ApproximateMessageCount 在调用 FetchAttributesAsync 后仍然停留在 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 的决心:-(。

我错过了什么吗?

【问题讨论】:

    标签: azure win-universal-app azure-queues


    【解决方案1】:

    我认为您在存储客户端库中发现了一个错误。我在 Github 上查找了代码,实际上不是读取 Approximate Message Count 标头的值,而是读取 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      • 2018-12-18
      • 2021-01-29
      • 1970-01-01
      相关资源
      最近更新 更多