问题
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