如何枚举所有分区并聚合结果

时间:2016-06-12 13:46:55

标签: azure-service-fabric

我有一个多分区的有状态服务。如何使用service remoting枚举客户端和服务之间的通信来枚举其所有分区并汇总结果?

1 个答案:

答案 0 :(得分:11)

您可以使用FabricClient枚举分区:

var serviceName = new Uri("fabric:/MyApp/MyService");
using (var client = new FabricClient())
{
    var partitions = await client.QueryManager.GetPartitionListAsync(serviceName);

    foreach (var partition in partitions)
    {
        Debug.Assert(partition.PartitionInformation.Kind == ServicePartitionKind.Int64Range);
        var partitionInformation = (Int64RangePartitionInformation)partition.PartitionInformation;
        var proxy = ServiceProxy.Create<IMyService>(serviceName, new ServicePartitionKey(partitionInformation.LowKey));
        // TODO: call service
    }
}

请注意,您应该缓存GetPartitionListAsync的结果,因为如果不重新创建服务就无法更改服务分区(您可以保留LowKey值列表)。

此外,还应尽可能分享FabricClient(请参阅documentation)。

相关问题