【发布时间】:2016-10-12 23:58:49
【问题描述】:
我有一个多分区的有状态服务。如何枚举其所有分区并聚合结果,使用service remoting 进行客户端和服务之间的通信?
【问题讨论】:
我有一个多分区的有状态服务。如何枚举其所有分区并聚合结果,使用service remoting 进行客户端和服务之间的通信?
【问题讨论】:
您可以使用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)。
【讨论】:
LowKey 值列表是个好主意。谢谢你。
FabricClient 是什么意思?
FabricClient的实例。