【问题标题】:How to enable read from StatefulService secondary replicas?如何启用从 StatefulService 辅助副本读取?
【发布时间】:2016-07-02 03:45:55
【问题描述】:

许多官方 Service Fabric 文章指出应该可以对辅助副本执行读取操作,但我找不到显示如何配置或使用此高级功能的单个代码示例。

一个很好的例子是详细说明这个简单的代码示例:https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/AlphabetPartitions

对辅助节点的读取只是 HTTP Get 操作。

我想用它来扩展 StatefulServices 上的读取密集型操作。

【问题讨论】:

    标签: azure-service-fabric


    【解决方案1】:

    在这篇文章中找到了答案:How to use the Reliable Services communication APIs

    可以在 ServiceReplicaListener 类的构造函数中使用名为 listenOnSecondary 的参数启用对辅助副本的读取。

    本文中的代码示例如下所示,使用命名参数进行了调整:

    protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return new[]
        {
            new ServiceReplicaListener(context =>
                new MyCustomListener(context),
                "customReadonlyEndpoint",
                listenOnSecondary:true),
    
            new ServiceReplicaListener(context =>
                this.CreateServiceRemotingListener(context),
                "rpcPrimaryEndpoint",
                listenOnSecondary:false)
        };
    }
    

    【讨论】:

    • 有没有办法验证我实际上是从辅助副本中读取的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    相关资源
    最近更新 更多