Service Fabric reverse proxy port configurability

守給你的承諾、 提交于 2019-12-07 15:36:32

After some time spent in the object browser I was able to find the various pieces I needed to make this properly.

public class ReverseProxyPortResolver
{
    /// <summary>
    /// Represents the port that the current fabric node is configured
    /// to use when using a reverse proxy on localhost
    /// </summary>
    public static AsyncLazy<int> ReverseProxyPort = new AsyncLazy<int>(async ()=>
    {
        //Get the cluster manifest from the fabric client & deserialize it into a hardened object
        ClusterManifestType deserializedManifest;
        using (var cl = new FabricClient())
        {
            var manifestStr = await cl.ClusterManager.GetClusterManifestAsync().ConfigureAwait(false);
            var serializer = new XmlSerializer(typeof(ClusterManifestType));

            using (var reader = new StringReader(manifestStr))
            {
                deserializedManifest = (ClusterManifestType)serializer.Deserialize(reader);
            }
        }

        //Fetch the setting from the correct node type
        var nodeType = GetNodeType();
        var nodeTypeSettings = deserializedManifest.NodeTypes.Single(x => x.Name.Equals(nodeType));
        return int.Parse(nodeTypeSettings.Endpoints.HttpApplicationGatewayEndpoint.Port);
    });

    private static string GetNodeType()
    {
        try
        {
            return FabricRuntime.GetNodeContext().NodeType;
        }
        catch (FabricConnectionDeniedException)
        {
            //this code was invoked from a non-fabric started application
            //likely a unit test
            return "NodeType0";
        }

    }
}

News to me in this investigation was that all of the schemas for any of the service fabric xml is squirreled away in an assembly named System.Fabric.Management.ServiceModel.

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