通过ServiceProxy客户端

时间:2016-06-09 08:51:09

标签: azure-service-fabric

我已将两个无状态SinglePartion微服务部署到Service Fabric群集中,这些群集托管在Azure上。现在我想连接这些服务之间的通信:enter image description here

我的 Masterdata Web API服务在通过ServiceProxy客户端调用方法时,应该更喜欢在同一节点上与 Masterdata ServiceProxy Service 副本/实例进行通信。如果同一节点上没有可用的副本/实例,请连接到另一个节点。代码如下所示:

var serviceClient = ServiceProxy.Create<IMasterDataServiceProxy>(new Uri("fabric:/sfApp/MasterDataServiceProxy"));
var result = await serviceClient.GetMasterData();

但实际上沟通是这样的:

enter image description here

ServiceProxy连接到随机选择的副本/实例(由于TargetReplicaSelector.Default)。我错过了一些通信选项,如“TargetReplicaSelector.PreferSameNode”。有没有办法手动处理这个?

2 个答案:

答案 0 :(得分:4)

这里有一个很好的解释: How can I reach a specific replica of a stateless service

如果你真的想要它,

  • 在localhost或
  • 上使用http侦听器
  • 使用有状态服务(使用StateManager是可选的)

答案 1 :(得分:3)

不使用Service Remoting(ServiceProxy),但确保HTTP!只需获取当前节点IP并向您的其他服务URL发出请求。

当然,这确实意味着您的Masterdata ServiceProxy服务必须更改为Masterdata Web API服务。

相关问题