Targeting a stateless replica on the same node when communicating over the ServiceProxy client

China☆狼群 提交于 2019-12-11 04:25:25

问题


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:

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:

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?


回答1:


Here's a good explanation: How can I reach a specific replica of a stateless service

If you still really want it, either

  • use http listeners on localhost or
  • use a stateful service (using StateManager is optional)



回答2:


Not with Service Remoting (ServiceProxy), but with HTTP sure! Just grab the current node IP and make a request to your other service URL.

Of course, that does mean your Masterdata ServiceProxy Service would have to change to a Masterdata Web API Service.



来源:https://stackoverflow.com/questions/37721138/targeting-a-stateless-replica-on-the-same-node-when-communicating-over-the-servi

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