如何启用从 StatefulService 辅助副本读取?
How to enable read from StatefulService secondary replicas?
许多官方 Service Fabric 文章指出应该可以在辅助副本上执行读取操作,但我找不到一个代码示例来说明如何配置或使用此高级功能。
一个很好的例子是详细说明这个简单的代码示例:https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/AlphabetPartitions
在辅助节点上读取只是 HTTP Get 操作。
我想用它来扩展 StatefulServices 上的读取密集型操作。
在这篇文章中找到了答案:How to use the Reliable Services communication APIs
可以在 ServiceReplicaListener class 的构造函数中使用名为 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)
};
}
许多官方 Service Fabric 文章指出应该可以在辅助副本上执行读取操作,但我找不到一个代码示例来说明如何配置或使用此高级功能。
一个很好的例子是详细说明这个简单的代码示例:https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/AlphabetPartitions
在辅助节点上读取只是 HTTP Get 操作。
我想用它来扩展 StatefulServices 上的读取密集型操作。
在这篇文章中找到了答案:How to use the Reliable Services communication APIs
可以在 ServiceReplicaListener class 的构造函数中使用名为 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)
};
}