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

How to enumerate all partitions and aggregate results

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

您可以使用 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)。