How to enumerate all partitions and aggregate results

后端 未结 1 1254
别那么骄傲
别那么骄傲 2021-01-13 04:39

I have a multiple partitioned stateful service. How can I enumerate all its partitions and aggregate results, using service remoting for communication between client and ser

相关标签:
1条回答
  • 2021-01-13 05:11

    You can enumerable the partitions using 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
        }
    }
    

    Note that you should probably cache the results of GetPartitionListAsync since service partitions cannot be changed without recreating the service (you can just keep a list of the LowKey values).

    In addition, FabricClient should also be shared as much as possible (see the documentation).

    0 讨论(0)
提交回复
热议问题