ApproximateMessageCount always null after calling

2019-06-27 01:46发布

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).

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).

Console code:

        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}");
            }
        }

Universal App code:

        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!!!
        }

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 :-(.

Am I missing something?

1条回答
爷、活的狠高调
2楼-- · 2019-06-27 02:41

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.

In QueueHttpResponseParsers.cs class:

    public static string GetApproximateMessageCount(HttpResponseMessage response)
    {
        return response.Headers.GetHeaderSingleValueOrDefault(Constants.HeaderConstants.LeaseStatus);
    }

This method should have been:

    public static string GetApproximateMessageCount(HttpResponseMessage response)
    {
        return response.Headers.GetHeaderSingleValueOrDefault(Constants.HeaderConstants.ApproximateMessagesCount);
    }

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

查看更多
登录 后发表回答