【问题标题】:How to enumerate all partitions and aggregate results如何枚举所有分区并聚合结果
【发布时间】:2016-10-12 23:58:49
【问题描述】:

我有一个多分区的有状态服务。如何枚举其所有分区并聚合结果,使用service remoting 进行客户端和服务之间的通信?

【问题讨论】:

    标签: azure-service-fabric


    【解决方案1】:

    您可以使用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 是什么意思?
    • @jugg1es 意思是不用每次都新建一个,而是复用FabricClient的实例。
    猜你喜欢
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2016-11-26
    相关资源
    最近更新 更多