如何枚举所有分区并汇总结果 [英] How to enumerate all partitions and aggregate results

查看:129
本文介绍了如何枚举所有分区并汇总结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个分区的有状态服务.如何使用服务远程处理,用于客户端和服务之间的通信?

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

这篇关于如何枚举所有分区并汇总结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆