首页 文章

Service Fabric反向代理端口可配置性

提问于
浏览
1

我正在尝试编写一个封装来获取服务结构的本地反向代理的uri,并且我很难决定如何处理端口的可配置性(在服务清单中称为“HttpApplicationGatewayEndpoint”或“在arm模板中的“reverseProxyEndpointPort” . 我认为这样做的最好方法是从结构客户端调用“GetClusterManifestAsync”并从那里解析它,但由于某些原因我也不喜欢它 . 例如,该调用返回一个字符串xml blob,该字符串没有防止对清单模式的更改 . 我还没有找到一种方法来查询集群管理器以找出我当前所在的节点类型,因此如果出于某种愚蠢的原因,集群有多个节点类型,并且每个节点类型都有不同的反向代理端口(仅仅是这里的防御性编码器,可能会失败 . 动态发现端口号似乎是一项非常大的努力,而且我之前绝对错过了Fabric api中的内容,所以有关如何解决这个问题的任何建议?

编辑:

我从示例项目中看到它从服务中的配置包中获取端口号 . 我宁愿不必这样做,因为那时我将不得不为每个需要使用它来阅读配置并传递它的服务编写大量样板文件 . 由于这在运行时或多或少是常量,所以在我看来,这样可以这样处理并从结构客户端获取某个地方?

1 回答

  • 2

    在对象浏览器中花了一些时间之后,我能够找到正确完成此操作所需的各种部分 .

    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";
            }
    
        }
    }
    

    在这次调查中,我得到的消息是,任何服务结构xml的所有模式都在一个名为 System.Fabric.Management.ServiceModel 的程序集中被捕获 .

相关问题