How to enumerate all partitions and aggregate results

自作多情 提交于 2019-12-01 05:12:02

问题


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 service?


回答1:


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).



来源:https://stackoverflow.com/questions/37774965/how-to-enumerate-all-partitions-and-aggregate-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!