"result segment" 在 CloudQueueClient Class 中的含义
Meaning of "result segment" in CloudQueueClient Class
我看到很多参考文献在 CloudQueueClient Class 中提到术语 "result segment",例如在方法 "ListQueuesSegmented" 和 "ListQueuesSegmentedAsync" 中。但是我没有找到任何关于如何使用这些功能的有意义的例子。任何 Azure 专家都可以解释一下吗?
谢谢
德里克
创建存储帐户时,可以在其中创建无限数量的队列(有关详细信息,请参阅storage limits)。
假设您想获取有关所有队列的信息,您可以使用 CloudQueueClient.ListQueues
方法遍历所有队列:
var storageAccount = CloudStorageAccount.Parse("MyConnectionString");
var queueClient = storageAccount.CreateCloudQueueClient();
foreach(var queue in queueClient.ListQueues())
{
// Do something
}
假设您有上千个队列,您可能不想执行此请求,因为它可能会超时,达到某些限制。
即Segmented
方法的全部目的。它将 return 前 X 个元素 + 一个允许您请求下一个 X 元素的令牌。
当你使用table显示数据时(在UI这边),有时你不得不使用分页,因为你的table可能太大而无法完整显示:这是相同的概念。
所以现在如果你想使用它:
// Initialize a new token
var continuationToken = new QueueContinuationToken();
// Execute the query
var segment = queueClient.ListQueuesSegmented(continuationToken);
// Get the new token in order to get the next segment
continuationToken = segment.ContinuationToken;
// Get the results
var queues = segment.Results.ToList();
// do something
...
// Execute the query again with the comtinuation token to fetch next results
segment = queueClient.ListQueuesSegmented(continuationToken);
中有如何使用这些函数的示例
关于如何通过 ListQueuesSegmentedAsync 进行分页的具体方法是:(注意初始化为空令牌似乎是正确的,检测用于结束链的空令牌也是正确的)
Console.WriteLine(string.Empty);
Console.WriteLine("List of queues in the storage account:");
// List the queues for this storage account
QueueContinuationToken token = null;
List<CloudQueue> cloudQueueList = new List<CloudQueue>();
do
{
QueueResultSegment segment = await cloudQueueClient.ListQueuesSegmentedAsync(token);
token = segment.ContinuationToken;
cloudQueueList.AddRange(segment.Results);
}
while (token != null);
我看到很多参考文献在 CloudQueueClient Class 中提到术语 "result segment",例如在方法 "ListQueuesSegmented" 和 "ListQueuesSegmentedAsync" 中。但是我没有找到任何关于如何使用这些功能的有意义的例子。任何 Azure 专家都可以解释一下吗?
谢谢
德里克
创建存储帐户时,可以在其中创建无限数量的队列(有关详细信息,请参阅storage limits)。
假设您想获取有关所有队列的信息,您可以使用 CloudQueueClient.ListQueues
方法遍历所有队列:
var storageAccount = CloudStorageAccount.Parse("MyConnectionString");
var queueClient = storageAccount.CreateCloudQueueClient();
foreach(var queue in queueClient.ListQueues())
{
// Do something
}
假设您有上千个队列,您可能不想执行此请求,因为它可能会超时,达到某些限制。
即Segmented
方法的全部目的。它将 return 前 X 个元素 + 一个允许您请求下一个 X 元素的令牌。
当你使用table显示数据时(在UI这边),有时你不得不使用分页,因为你的table可能太大而无法完整显示:这是相同的概念。
所以现在如果你想使用它:
// Initialize a new token
var continuationToken = new QueueContinuationToken();
// Execute the query
var segment = queueClient.ListQueuesSegmented(continuationToken);
// Get the new token in order to get the next segment
continuationToken = segment.ContinuationToken;
// Get the results
var queues = segment.Results.ToList();
// do something
...
// Execute the query again with the comtinuation token to fetch next results
segment = queueClient.ListQueuesSegmented(continuationToken);
关于如何通过 ListQueuesSegmentedAsync 进行分页的具体方法是:(注意初始化为空令牌似乎是正确的,检测用于结束链的空令牌也是正确的)
Console.WriteLine(string.Empty);
Console.WriteLine("List of queues in the storage account:");
// List the queues for this storage account
QueueContinuationToken token = null;
List<CloudQueue> cloudQueueList = new List<CloudQueue>();
do
{
QueueResultSegment segment = await cloudQueueClient.ListQueuesSegmentedAsync(token);
token = segment.ContinuationToken;
cloudQueueList.AddRange(segment.Results);
}
while (token != null);