【问题标题】:Error consume route ApiGateway with ocelot and docker service使用 ocelot 和 docker 服务使用路由 ApiGateway 时出错
【发布时间】:2021-03-28 09:16:04
【问题描述】:

我正在使用 ocelot 创建一个 ApiGateway,它使用网络核心中的 Api 服务。 ApiGateway 和 ApiService 部署在 docker 上,docker compose 是这样的: Docker-compose

tresfilos.webapigateway:
image: ${DOCKER_REGISTRY-}tresfilosapigateway
build: 
  context: .
  dockerfile: tresfilos.ApiGateway/ApiGw-Base/Dockerfile

tresfilos.users.service:
image: ${DOCKER_REGISTRY-}tresfilosusersservice
build: 
  context: .
  dockerfile: tresfilos.Users.Service/tresfilos.Users.Service/Dockerfile

Docker-compose.override

tresfilos.webapigateway:
environment: 
  - ASPNETCORE_ENVIRONMENT=Development
  - IdentityUrl=http://identity-api
ports:
  - "7000:80"
  - "7001:443"
volumes:
  - ./tresfilos.ApiGateway/Web.Bff:/app/configuration

tresfilos.users.service:
environment: 
  - ASPNETCORE_ENVIRONMENT=Development
  - ASPNETCORE_URLS=https://+:443;http://+:80
ports:
  - "7002:80"
  - "7003:443"
volumes:
  - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
  - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

configuration ocelot apigateway 我定义 .json 像:

 "ReRoutes": [
 {
   "DownstreamPathTemplate": "/api/{version}/{everything}",
   "DownstreamScheme": "http",
   "DownstreamHostAndPorts": [
     {
       "Host": "tresfilos.users.service",
       "Port": 7002
     }
   ],
   "UpstreamPathTemplate": "/api/{version}/user/{everything}",
   "UpstreamHttpMethod": [ "POST", "PUT", "GET" ]
 },
],
"GlobalConfiguration": {
  "BaseUrl":  "https://localhost:7001"
 }

当我从 url 使用 ApiGateway 时: http://localhost:7000/api/v1/user/Login/authentication

我在终端 docker 中有错误:

为什么会出现上述错误以及如何解决?

【问题讨论】:

    标签: docker asp.net-core routes api-gateway ocelot


    【解决方案1】:

    你运行的是什么版本的 Ocelot?

    我发现另一个有类似问题的线程,显然从 16.0.0 版的 Ocelot 'ReRoutes' 在 Ocelot 配置文件中更改为 'Routes'。

    我找到的线程是-404 trying to route the Upstream path to downstream path in Ocelot

    【讨论】:

    • 版本 16.0.1,当更改为 Routes 时会产生错误
    • 将其更改为 Routes 后会出现什么错误?
    • System.AggregateException: '发生一个或多个错误。 (无法启动Ocelot,错误为:Authentication Options AuthenticationProviderKey:IdentityApiKey,AllowedScopes:[] is unsupported authentication provider)'
    【解决方案2】:

    我是这样解决的:

    1. 将 ReRoutes 更改为 Routes,因为 ocelot 版本是 16.0.1

    2. 定义如下配置:

      “路线”:[ { "DownstreamPathTemplate": "/api/{version}/{everything}", "DownstreamScheme": "http", “下游主机和端口”:[ { “主机”:“tresfilos.users.service”, “端口”:7002 } ], "UpstreamPathTemplate": "/api/{version}/User/{everything}" }, ], “全局配置”:{ “BaseUrl”:“https://localhost:7001” }

    3. 在邮递员中,我像 json 一样发送 Body 中的数据,而不是像参数一样。

    (JasonS 谢谢)...

    【讨论】:

      猜你喜欢
      • 2019-03-20
      • 2015-02-25
      • 2021-06-01
      • 2021-01-22
      • 2016-12-23
      • 2018-10-19
      • 1970-01-01
      • 2023-01-28
      • 2020-06-05
      相关资源
      最近更新 更多