在Universal Windows应用程序中调用FetchAttributesAsync后,roximateMessageCount始终为null [英] ApproximateMessageCount always null after calling FetchAttributesAsync in a Universal windows App

查看:108
本文介绍了在Universal Windows应用程序中调用FetchAttributesAsync后,roximateMessageCount始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a small App that should list the number of items in my Azure queues. When I use FetchAttributesAsync and ApproximateMessageCount in a Console App, I get the expected result in ApproximateMessageCount after a call to FetchAttributesAsync (or FetchAttributes).

当我使用与通用Windows应用程序中的相同,在调用FetchAttributesAsync(FetchAttributes在此处不可用)之后,近似消息计数仍停留在 null 处。

When I use the same in a Universal Windows app, ApproximateMessageCount remains stuck at null after a call to FetchAttributesAsync (FetchAttributes is not available there).

控制台代码:

        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()等在等待中。无论我尝试什么, roximateMessageCount 都将保持 null 并终止:-(。

I have tried all kinds of alternatives, like Wait()'s and such on the awaitables. Whatever I try, the ApproximateMessageCount stays a null with dertermination :-(.

我缺少什么吗?

推荐答案

我认为您在存储客户端库中发现了一个错误。在Github上查找代码,本质上不是读取近似消息计数标头的值,而是读取租赁状态标头。

I think you have discovered a bug in the storage client library. I looked up the code on Github and essentially instead of reading the value for Approximate Message Count header, the code is reading the value for Lease Status header.

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

I have submitted a bug for this: https://github.com/Azure/azure-storage-net/issues/155.

这篇关于在Universal Windows应用程序中调用FetchAttributesAsync后,roximateMessageCount始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆