首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法合并Ocelot配置文件

无法合并Ocelot配置文件
EN

Stack Overflow用户
提问于 2021-04-12 18:49:24
回答 3查看 294关注 0票数 7

根据documentation,我尝试合并我的配置文件,以使它们更具可读性。但是,生成的ocelot.json文件并不像预期的那样。我的文件夹结构如下:

Folder structure

下面是这方面的文本表示:

代码语言:javascript
复制
.
└── Ocelot route configs
    ├── ocelot.pokemon.json
    ├── ocelot.tweet.json
    └── ocelot.weather.json

ocelot.pokemon.json文件如下所示(其他文件如下所示):

代码语言:javascript
复制
{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/v2/pokemon",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "pokeapi.co",
          "Port": 443
        }
      ],
      "UpstreamPathTemplate": "/api/pokemon",
      "UpstreamHttpMethod": [ "GET" ],
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "MyTestKey",
        "AllowedScopes": []
      }
    },
    {
      "DownstreamPathTemplate": "/api/v2/pokemon/ditto",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "pokeapi.co",
          "Port": 443
        }
      ],
      "UpstreamPathTemplate": "/api/pokemon/ditto",
      "UpstreamHttpMethod": [ "GET" ]
    }
  ]
}

生成的ocelot.json文件如下所示:

代码语言:javascript
复制
{
  "Routes": [
  ],
  "DynamicRoutes": [
  ],
  "Aggregates": [
  ],
  "GlobalConfiguration": {
    "RequestIdKey": null,
    "ServiceDiscoveryProvider": {
      "Scheme": null,
      "Host": null,
      "Port": 0,
      "Type": null,
      "Token": null,
      "ConfigurationKey": null,
      "PollingInterval": 0,
      "Namespace": null
    },
    "RateLimitOptions": {
      "ClientIdHeader": "ClientId",
      "QuotaExceededMessage": null,
      "RateLimitCounterPrefix": "ocelot",
      "DisableRateLimitHeaders": false,
      "HttpStatusCode": 429
    },
    "QoSOptions": {
      "ExceptionsAllowedBeforeBreaking": 0,
      "DurationOfBreak": 0,
      "TimeoutValue": 0
    },
    "BaseUrl": null,
    "LoadBalancerOptions": {
      "Type": null,
      "Key": null,
      "Expiry": 0
    },
    "DownstreamScheme": null,
    "HttpHandlerOptions": {
      "AllowAutoRedirect": false,
      "UseCookieContainer": false,
      "UseTracing": false,
      "UseProxy": true,
      "MaxConnectionsPerServer": 2147483647
    },
    "DownstreamHttpVersion": null
  }
}

如您所见,我定义的路由并未添加。我试着在互联网上寻找这个特定的问题,但什么也找不到。我不知道我做错了什么,感谢你的帮助。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-04-12 20:02:36

由于不同的路由配置文件位于一个文件夹中,因此您应该确保调用了正确的AddOcelot方法重载。在这种情况下,应该使用包含路由文件的文件夹名称调用该方法。

例如:

代码语言:javascript
复制
config.AddOcelot("Ocelot route configs", hostingContext.HostingEnvironment)
票数 6
EN

Stack Overflow用户

发布于 2021-07-17 05:31:48

更新:支持Ocelot 17.0.0.NET Core 3+

因为方法AddOcelot需要一个IWebHostEnvironment,而这在HostBuilderContext中不可用

您需要通过WebHostBuilderContext获取

代码语言:javascript
复制
票数 2
EN

Stack Overflow用户

发布于 2021-07-17 16:34:22

我创建了两个不同的目录Development和Production,使用下面的代码,我能够根据开发环境读取ocelot配置,以生成将由ocelot中间件使用的最终ocelot.json。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67057050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档