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

akr*_*smv 4 azure-service-fabric

我有一个多分区的有状态服务.如何使用服务远程处理客户端和服务之间的通信来枚举其所有分区和聚合结果?

Eli*_*bel 12

您可以使用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
    }
}
Run Code Online (Sandbox Code Playgroud)

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

此外,FabricClient还应尽可能共享(参见文档).