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

Posted

技术标签:

【中文标题】Service Fabric 反向代理端口可配置性【英文标题】:Service Fabric reverse proxy port configurability 【发布时间】:2017-10-16 04:23:06 【问题描述】:

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

编辑:

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

【问题讨论】:

【参考方案1】:

在对象浏览器中花费了一段时间后,我能够找到正确制作所需的各个部分。

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 的程序集中。

【讨论】:

以上是关于Service Fabric 反向代理端口可配置性的主要内容,如果未能解决你的问题,请参考以下文章

如何为现有的本地集群配置和启用 Azure Service Fabric 反向代理?

Service Fabric 反向代理 - 404 - FABRIC_E_SERVICE_DOES_NOT_EXIST

创建 Service Fabric 群集后启用反向代理

使用 https 的 Service Fabric 反向代理

API(网关)提供的反向代理和Service Fabric有啥区别?

如何让 Service Fabric 反向代理在 Azure 上工作