根据documentation,我尝试合并我的配置文件,以使它们更具可读性。但是,生成的ocelot.json文件并不像预期的那样。我的文件夹结构如下:
下面是这方面的文本表示:
.
└── Ocelot route configs
├── ocelot.pokemon.json
├── ocelot.tweet.json
└── ocelot.weather.jsonocelot.pokemon.json文件如下所示(其他文件如下所示):
{
"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文件如下所示:
{
"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
}
}如您所见,我定义的路由并未添加。我试着在互联网上寻找这个特定的问题,但什么也找不到。我不知道我做错了什么,感谢你的帮助。
发布于 2021-04-12 20:02:36
由于不同的路由配置文件位于一个文件夹中,因此您应该确保调用了正确的AddOcelot方法重载。在这种情况下,应该使用包含路由文件的文件夹名称调用该方法。
例如:
config.AddOcelot("Ocelot route configs", hostingContext.HostingEnvironment)发布于 2021-07-17 05:31:48
更新:支持Ocelot 17.0.0的.NET Core 3+
因为方法AddOcelot需要一个IWebHostEnvironment,而这在HostBuilderContext中不可用

您需要通过WebHostBuilderContext获取

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

https://stackoverflow.com/questions/67057050
复制相似问题