gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:05:50 25 4
gpt4 key购买 nike

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

编辑:

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

最佳答案

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

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

关于azure - Service Fabric 反向代理端口可配置性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44012427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com