通过ServiceProxy客户端进行通信时,将无状态副本定位到同一节点上 [英] Targeting a stateless replica on the same node when communicating over the ServiceProxy client
问题描述
我已将两个 Stateless 和SinglePartion
微服务部署到Service Fabric群集中,这些服务托管在Azure上.现在,我想像这样连接这些服务之间的通信:
I have deployed two Stateless and SinglePartion
Microservices into a Service Fabric cluster, which are hosted on Azure. Now I want to hook up the communication between these services like this:
当通过ServiceProxy客户端调用方法时,我的 Masterdata Web API服务应该更喜欢与同一节点上的 Masterdata ServiceProxy服务副本/实例进行通信.如果同一节点上没有可用的副本/实例,请连接到另一个节点.代码如下:
My Masterdata Web API Service should prefer to communicate with a Masterdata ServiceProxy Service replica/instance on the same node when calling a method via the ServiceProxy client. If there's no replica/instance available on the same node, connect to another node. The code looks like this:
var serviceClient = ServiceProxy.Create<IMasterDataServiceProxy>(new Uri("fabric:/sfApp/MasterDataServiceProxy"));
var result = await serviceClient.GetMasterData();
但是实际上交流是这样的:
But actually the communication is like this:
ServiceProxy连接到随机选择的副本/实例(由于TargetReplicaSelector.Default
).我缺少某些通信选项,例如"TargetReplicaSelector.PreferSameNode
".有什么办法可以手动处理吗?
The ServiceProxy connects to a randomly chosen replica/instance (due to TargetReplicaSelector.Default
). I'm missing some communication options like "TargetReplicaSelector.PreferSameNode
". Is there any way to handle this manually?
推荐答案
以下是一个很好的解释: 如何找到特定的无状态服务
Here's a good explanation: How can I reach a specific replica of a stateless service
如果您仍然很想要它,
- 在localhost或 上使用http侦听器
- 使用有状态服务(使用StateManager是可选的)
- use http listeners on localhost or
- use a stateful service (using StateManager is optional)
这篇关于通过ServiceProxy客户端进行通信时,将无状态副本定位到同一节点上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!