Service Fabric反向代理端口可配置性 [英] Service Fabric reverse proxy port configurability

查看:103
本文介绍了Service Fabric反向代理端口可配置性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个封装来获取服务结构的本地反向代理的uri,并且很难决定如何实现端口的可配置性(在服务中称为"HttpApplicationGatewayEndpoint"清单或臂模板中的"reverseProxyEndpointPort").我认为最好的方法是从结构客户端调用"GetClusterManifestAsync"并从那里解析它,但是出于某些原因,我也不喜欢这样做.首先,该调用返回一个字符串xml blob,该字符串不能防止对清单模式进行更改.我还没有找到一种查询集群管理器的方法来找出我当前正在使用的节点类型,因此,如果出于某种愚蠢的原因,集群具有多个节点类型,而每个节点都有一个不同的反向代理端口(只是防御性编码器),可能会导致失败.动态发现该端口号似乎需要花费很多精力,而且我之前肯定也错过了Fabric API中的工作,因此,关于如何解决此问题的任何建议吗?

I'm trying to write an encapsulation to get the uri for a local reverse proxy for service fabric and I'm having a hard time deciding how I want to approach configurability for the port (known as "HttpApplicationGatewayEndpoint" in the service manifest or "reverseProxyEndpointPort" in the arm template). The best way I've thought to do it would be to call "GetClusterManifestAsync" from the fabric client and parse it from there, but I'm also not a fan of that for a few reasons. For one, the call returns a string xml blob, which isn't guarded against changes to the manifest schema. I've also not yet found a way to query the cluster manager to find out which node type I'm currently on, so if for some silly reason the cluster has multiple node types and each one has a different reverse proxy port (just being a defensive coder here), that could potentially fail. It seems like an awful lot of effort to go through to dynamically discover that port number, and I've definitely missed things in the fabric api before, so any suggestions on how to approach this issue?

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

I'm seeing from the example project that it's getting the port number from a config package in the service. I would rather not have to do it that way as then I'm going to have to write a ton of boilerplate for every service that'll need to use this to read configs and pass this around. Since this is more or less a constant at runtime then it seems to me like this could be treated as such and fetched somewhere from the fabric client?

推荐答案

在对象浏览器中花费了一段时间后,我能够找到正确完成此设置所需的各种部件.

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

    }
}

在此调查中给我的消息是,任何服务结构xml的所有架构都在名为System.Fabric.Management.ServiceModel的程序集中被松散.

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.

这篇关于Service Fabric反向代理端口可配置性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆