本文介绍了如何枚举所有分区并汇总结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个分区的有状态服务.如何使用服务远程处理,用于客户端和服务之间的通信?
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?
推荐答案您可以使用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值的列表).
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).
此外,还应尽可能共享FabricClient(请参阅文档).
In addition, FabricClient should also be shared as much as possible (see the documentation).
更多推荐
如何枚举所有分区并汇总结果
发布评论