Search code examples
httpreverse-proxyazure-service-fabricservice-fabric-stateless

Intra ServiceFabric communication with internal reverse proxy on localhost


I have a ServiceFabric with two applications. On application gets invoked from outside the ServiceFabric and then issues HTTP get requests to the other application inside the ServiceFabric.

My first attempt was to address the second application with the ServiceFabric's reverse proxy IP, the same as the first application is addressed with:

http://10.0.0.1:19081/App2/App2.Service/

This led to unreliable communication inside the ServiceFabric and the first request always failed, while the second mostly succeeded.

Then I read about internal ServiceFabric communication at https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reverseproxy. Now I address my second application with localhost and it seems to work as expected:

http://localhost:19081/App2/App2.Service/

The only open question is: Does addressing applications inside the ServiceFabric with localhost only work because the application is also running on the same node? Or does it work because there is real reverse proxy behavior and even if the application does not run on the same node, the request gets to it regardless?


Solution

  • The reverse proxy runs on all nodes, so it can be reached on localhost at all times. It forwards your call to the second service, which is resolved automatically.

    You could also use the built-in DNS service to resolve internal services. This way, you save some of the overhead of the reverse proxy. Opposed to using the ip address, you don't need to know whether the service runs on localhost or on a different node. Also, you don't get into trouble if your service is moved at run-time.