How to enable read from StatefulService secondary replicas?

心已入冬 提交于 2019-12-09 07:33:25

问题


Many of the official Service Fabric articles states that it should be possible to do read operations on secondary replicas, but I am unable to find a single code example that shows how to configure or use this advanced feature.

A good example would be to elaborate on this simple code sample: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/AlphabetPartitions

Where reads on secondaries are just HTTP Get operations.

I would like to use it as a way to scale out read intensive operations on StatefulServices.


回答1:


Found the answer in this article: How to use the Reliable Services communication APIs

It is possible to enable reads on secondary replicas using a parameter called listenOnSecondary in the constructor of the ServiceReplicaListener class.

The code sample found in the article is shown here, tweaked with named parameters:

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)
    };
}


来源:https://stackoverflow.com/questions/38152271/how-to-enable-read-from-statefulservice-secondary-replicas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!