Ocelot 找不到重新路由文件
Ocelot not finding reroutes files
我正在尝试构建自己的微服务架构,但卡在了 API.Gateway 部分。
我试图让 Ocelot V14 在 中找到所有配置 ocelot.json 或 configuration.json 文件。 sln 文件.
在 Program.cs 文件中,我试图将配置文件与此 link https://ocelot.readthedocs.io/en/latest/features/configuration.html#react-to-configuration-changes[=15= 中的以下代码合并]
builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddOcelot(hostingContext.HostingEnvironment)
.AddEnvironmentVariables();
})
.UseStartup<Startup>();
当我 运行 此应用程序在我的 OcelotApiGw 项目[= 中创建以下 ocelot.json 文件15=]
{
"ReRoutes": [
]
}
问题是它是空的,重新路由不起作用。当我将所需的重新路由粘贴到此 ocelot.json 文件时,重新路由起作用,这不是我想要的功能。
我想要的是从不同的 .json 文件自动合并配置文件。
如有任何帮助,我们将不胜感激。
eShopOnContainers 如何使用 Ocelot V12 以这种方式实现它
IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);
builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
.UseStartup<Startup>();
如果您需要更多代码、文件结构或其他任何内容,请发表评论并询问。
不确定这是否是您要找的?这是Ocelot将多个路由文件合并在一起的方式
https://ocelot.readthedocs.io/en/latest/features/configuration.html#merging-configuration-files
我们不使用它,但这是我们定义启动的方式:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile(this.env.IsDevelopment() ? "ocelot.json" : "ocelot.octopus.json")
.AddEnvironmentVariables();
所以我们有标准的 appSettings 加上我们使用的 Ocelot,当我们的 Ocelot 实例部署到我们的 test/production envs(或只是我们的 test/local 环境时,Octopus 将转换我们想要的各种变量).
这似乎是定义对多个文件执行的操作的位:
In this scenario Ocelot will look for any files that match the pattern
(?i)ocelot.([a-zA-Z0-9]*).json and then merge these together. If you
want to set the GlobalConfiguration property you must have a file
called ocelot.global.json.
不确定您是否需要显式定义每个文件(除非它们可以通过 {env.EnvironmentName} 之类的变量定义),但这应该很容易测试。
对不起,如果我说错了,但希望这对您有所帮助。
我正在尝试构建自己的微服务架构,但卡在了 API.Gateway 部分。 我试图让 Ocelot V14 在 中找到所有配置 ocelot.json 或 configuration.json 文件。 sln 文件.
在 Program.cs 文件中,我试图将配置文件与此 link https://ocelot.readthedocs.io/en/latest/features/configuration.html#react-to-configuration-changes[=15= 中的以下代码合并]
builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddOcelot(hostingContext.HostingEnvironment)
.AddEnvironmentVariables();
})
.UseStartup<Startup>();
当我 运行 此应用程序在我的 OcelotApiGw 项目[= 中创建以下 ocelot.json 文件15=]
{
"ReRoutes": [
]
}
问题是它是空的,重新路由不起作用。当我将所需的重新路由粘贴到此 ocelot.json 文件时,重新路由起作用,这不是我想要的功能。
我想要的是从不同的 .json 文件自动合并配置文件。
如有任何帮助,我们将不胜感激。
eShopOnContainers 如何使用 Ocelot V12 以这种方式实现它
IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);
builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
.UseStartup<Startup>();
如果您需要更多代码、文件结构或其他任何内容,请发表评论并询问。
不确定这是否是您要找的?这是Ocelot将多个路由文件合并在一起的方式
https://ocelot.readthedocs.io/en/latest/features/configuration.html#merging-configuration-files
我们不使用它,但这是我们定义启动的方式:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile(this.env.IsDevelopment() ? "ocelot.json" : "ocelot.octopus.json")
.AddEnvironmentVariables();
所以我们有标准的 appSettings 加上我们使用的 Ocelot,当我们的 Ocelot 实例部署到我们的 test/production envs(或只是我们的 test/local 环境时,Octopus 将转换我们想要的各种变量).
这似乎是定义对多个文件执行的操作的位:
In this scenario Ocelot will look for any files that match the pattern (?i)ocelot.([a-zA-Z0-9]*).json and then merge these together. If you want to set the GlobalConfiguration property you must have a file called ocelot.global.json.
不确定您是否需要显式定义每个文件(除非它们可以通过 {env.EnvironmentName} 之类的变量定义),但这应该很容易测试。
对不起,如果我说错了,但希望这对您有所帮助。