Freigeben über


Service Fabric Reverse Proxy Port discovery

Hello World!

The reverse proxy is a feature of Service Fabric that allows to expose internal endpoints, taking care of naming resolution, discovery and maintenance. Basically each service can be reached using an URI like:

https://cluster-fqdn:PORT/[ApplicationName]/[ServiceName]

In this Uri PORT is the Reverse Proxy port, ApplicationName is the name of the deployed application (root of many services) and ServiceName is the name of the single service inside the application package.

Unfortunately the reverse proxy port is not fixed! It depends from the node where the application is running, so it can even change during the application lifetime. This because the port is defined by the node type, so if the application change node type it changes the port.

To avoid this you can force an application to be deployment only on a specific node type:

 <PlacementConstraints>
 NodeType == NodeType2
</PlacementConstraints>

By the way even with a fixed node type, the port is not "well-known" and can change from cluster to cluster (as it is defined in the cluster config).

If you need to get the port by code at runtime unfortunately  there isn't an easy way yet. Basically you need to manually parse the xml cluster manifest, get the list of the node types, find the type where your application is deployed and then read the properties of the HttpApplicationGatewayEndpoint element.

You can check the code needed for this looking at this simple project: SFHelper

Also published as nuget package : https://www.nuget.org/packages/SFHelper/

Comments

  • Anonymous
    September 11, 2017
    I have been playing with Service Fabric Application Gateway recently and this post doesn't reflect what I've learned.When you deploy/configure your cluster, you define the Application Gateway port which by default is configured to be port 19081 and based on my understanding it doesn't change within the cluster or even during the lifetime of the application.Not only that by you use a different convention to access the application which is "http://cluster-fqdn:PORT/[Application Name]/[Service Name]/".I am not sure what yo umean by Application Deployment Name as there is no such thing that I've seen at least.
    • Anonymous
      September 11, 2017
      Hi,The Reverse Proxy port settings is per node type. When you create a new SF cluster in Azure in each node type blade you can configure the reverse proxy port.By default it proposes 19081, but you can customize it. So the right way is to consider that port different. If you do not use PlacementConstraints then the application can be moved between nodes (for example after a node failure) and therefore can change node type and potentially the reverse proxy port (if different).About the convention, i wanted to express in a different way the same meaning, I just updated per your suggestions as probably more easy to understand. thanks