2016-06-12 35 views

回答

9

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

+0

好主意保留'LowKey'值的列表。感谢那。 –

+0

“共享”“FabricClient”是什么意思? – jugg1es

+0

@ jugg1es这意味着您不必每次都创建一个新的'FabricClient'实例。 –