首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >服务结构反向代理端口配置

服务结构反向代理端口配置
EN

Stack Overflow用户
提问于 2017-05-16 22:09:27
回答 1查看 642关注 0票数 1

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

编辑:

我从示例项目中看到,它从服务中的一个配置包中获取端口号。我不想那样做,因为那样的话,我将不得不为每一项服务编写大量的样板,这些服务将需要用它来阅读和传递这些信息。由于这在运行时或多或少是一个常量,那么在我看来,它似乎可以这样处理,并从fabric客户端的某个地方获取?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-17 03:53:42

在对象浏览器中花费了一段时间之后,我能够找到我需要的各种片段来正确地完成这个任务。

代码语言:javascript
复制
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的程序集中。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44012427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档