【问题标题】:Azure service fabric with Ocelot API gateway 404 error带有 Ocelot API 网关 404 错误的 Azure 服务结构
【发布时间】:2019-02-21 01:26:02
【问题描述】:

我创建了包含多个无状态和有状态服务的 Azure 服务结构应用程序。我所有的有状态服务都可以通过 Web Api 无状态服务访问。现在我已将 Ocelot API 网关添加到另一个无状态 Web api 服务,我只想从该网关访问我的所有服务。现在,当我尝试从我的 API 网关服务访问服务时,它给了我 404。

Ocelot 配置

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/product/seed",
      "DownstreamScheme": "http",
      "UpstreamPathTemplate": "/api/product/randomize",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamHostAndPorts": [
        {
          "Host": "http://localhost:8314"
        }
      ],
      "QoSOptions": {
        "TimeoutValue": 360000
      }
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:8445"
  }
}

我在这里缺少什么?

【问题讨论】:

    标签: azure azure-service-fabric ocelot


    【解决方案1】:

    如果您在本地调试,则无需在主机配置手册中添加协议方案和端口,您可以从 Host 值中省略 HTTP 流量并为端口添加兄弟属性(参见下面的示例):

    {
      "DownstreamPathTemplate": "/api/user/",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.api.gateway",
          "Port": 52792
        }
      ],
      "UpstreamPathTemplate": "/api/user/",
      "UpstreamHttpMethod": [ "Get" ]
    },
    

    顺便说一句,我写了一篇关于 API 网关和 ASP.net Core + Ocelot 的 API 网关教程,如果您有兴趣了解更多关于 API 网关的信息,您可能想查看这篇文章:

    https://www.pogsdotnet.com/2018/08/api-gateway-in-nutshell.html

    希望对您有所帮助!
    艾伦

    【讨论】:

    猜你喜欢
    • 2018-12-29
    • 2021-07-17
    • 2020-12-16
    • 2017-03-30
    • 1970-01-01
    • 2020-10-20
    • 2017-09-14
    • 2020-07-25
    • 1970-01-01
    相关资源
    最近更新 更多