加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

azure – 在通用Windows应用程序中调用FetchAttributesAsync后,A

发布时间:2020-12-14 05:43:47 所属栏目:Windows 来源:网络整理
导读:我正在制作一个小应用程序,应该列出我的Azure队列中的项目数. 当我在Console App中使用FetchAttributesAsync和ApproximateMessageCount时,在调用FetchAttributesAsync(或FetchAttributes)之后,我在ApproximateMessageCount中得到了预期的结果. 当我在通用Win
我正在制作一个小应用程序,应该列出我的Azure队列中的项目数.
当我在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读