Azure 服务结构反向代理端口可配置性

Azure 服务结构反向代理端口可配置性,azure,azure-service-fabric,Azure,Azure Service Fabric,我正在尝试编写一个封装来获取service fabric的本地反向代理的uri,我很难决定如何实现端口的可配置性(在服务清单中称为“HttpApplicationGatewayEndpoint”,在arm模板中称为“ReverseProxy EndpointPort”)。我认为最好的方法是从fabric客户端调用“GetClusterManifestAsync”并从那里解析它,但出于几个原因,我也不喜欢这样做。首先,该调用返回一个字符串xml blob,它不会防止对清单模式的更改。我还没有找到一

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

编辑:


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

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

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

    }
}
公共类ReverseProxyPortResolver
{
/// 
///表示当前结构节点配置的端口
///在本地主机上使用反向代理时使用
/// 
公共静态AsyncLazy ReverseProxy端口=新建AsyncLazy(异步()=>
{
//从结构客户端获取集群清单&将其反序列化为一个强化对象
ClusterManifestType反序列化管理器;
使用(var cl=new FabricClient())
{
var manifestr=await cl.ClusterManager.GetClusterManifestAsync().ConfigureAwait(false);
var serializer=新的XmlSerializer(typeof(ClusterManifestType));
使用(var reader=newstringreader(manifestr))
{
deserializedManifest=(ClusterManifestType)序列化程序;
}
}
//从正确的节点类型获取设置
var nodeType=GetNodeType();
var nodeTypeSettings=deserializedManifest.NodeTypes.Single(x=>x.Name.Equals(nodeType));
返回int.Parse(nodeTypeSettings.Endpoints.HttpApplicationGatewayEndpoint.Port);
});
私有静态字符串GetNodeType()
{
尝试
{
返回FabriRuntime.GetNodeContext().NodeType;
}
捕获(FabricConnectionDexception)
{
//此代码是从非结构启动的应用程序调用的
//可能是单元测试
返回“NodeType0”;
}
}
}
在这次调查中,我得到的消息是,任何服务结构xml的所有模式都存储在名为
System.fabric.Management.ServiceModel
的程序集中