【发布时间】:2018-12-15 09:55:11
【问题描述】:
我在 Azure Service Fabric 集群中有一个 API Gateway 服务,我将其用作我的 Service Fabric 服务的网关。
这一切在我的机器上运行良好,在 Azure 的 1 节点集群中也是如此。
但是,当我在 5 节点集群中运行它时,我得到了错误
System.Net.Http.HttpRequestException:
An error occurred while sending the request. --->
System.Net.WebException: Unable to connect to the remote server
System.Net.Sockets.SocketException:
No connection could be made because the target machine actively refused it 127.0.0.1:19081
我知道 19081 是默认的反向代理端口。我在任何地方都没有看到任何关于专门解除阻塞此端口的说明,所以我假设它是打开的。
我很困惑为什么 127.0.0.1 可以在 1 节点集群中工作,但不能在 5 节点集群中工作。
我认为问题可能是我调用的服务并不总是与负载均衡器向其发送请求的 API 网关位于同一节点上。
我该如何解决这个问题?
我的 Price Service Fabric 服务有一个实例,可以在任何节点上。
我不能选择拥有多个价格服务实例。
有关信息,这是我使用的链接:
我要回去看看我是否遗漏了什么。
这是我用来获取数据的代码:
var proxyUrl = $"http://My Service Fabric URL:{this._configSettings.ReverseProxyPort}/{url.Replace("fabric:/", "")}/api/{Area}/{method}{parameters}";
Log.Information($"xUrl: {proxyUrl}");
var response = await this._httpClient.GetAsync(proxyUrl).ConfigureAwait(false);
var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (response.StatusCode != System.Net.HttpStatusCode.OK)
{
Log.Information($"{this.GetType().Name}: Error Response: {response.StatusCode}");
return this.StatusCode((int) response.StatusCode);
}
Log.Information(this.GetType().Name + ": Called API");
按照下面的建议,我现在有了获取地址的代码:
var resolver = ServicePartitionResolver.GetDefault();
var partition = await resolver.ResolveAsync(_serviceContext.ServiceName, ServicePartitionKey.Singleton, CancellationToken.None).ConfigureAwait(false);
var endpoints = JObject.Parse(partition.GetEndpoint().Address)["Endpoints"];
var address = endpoints[""].ToString().TrimEnd('/');
var proxyUrl = $"{address}:{this._configSettings.ReverseProxyPort}/{url.Replace("fabric:/", "")}/api/{Area}/{method}{parameters}";
这如何适应反向代理端口?
干杯
保罗
【问题讨论】:
标签: azure asp.net-web-api load-balancing azure-service-fabric