我有一个多分区的有状态服务。我怎样才能枚举它的所有分区和聚合结果,使用服务远程处理用于客户端和服务之间的通信?
您可以使用枚举分区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
还应该尽可能多地共享(请参阅文档).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)