.net core 2.1 шлюз ocelot возвращает 404

Я пытаюсь реализовать шлюз ocelot в своем приложении, но он всегда возвращает 404 на всех путях, которые я настроил в ocelot.json.

Всякий раз, когда я делаю GET на Postman, используя простые или совокупные вызовы, он всегда возвращает 404, и программа продолжает работать, она не дает сбоев.

Ocelot.json:

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/Buildings",
      "UpstreamPathTemplate": "/allBuildings",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5001
        }
      ],
      "Key": "Buildings"
    },
    {
      "DownstreamPathTemplate": "/api/Device",
      "UpstreamPathTemplate": "/allDevices",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5001
        }
      ],
      "Key": "Devices"
    }
  ],
  "Aggregates": [
    {
      "ReRouteKeys": [
        "Buildings",
        "Devices"
      ],
      "UpstreamPathTemplate": "/BAD",
      "Aggregator":  "FakeDefinedAggregator"
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "https://localhost:44351/"
  }
}

Program.cs:

 public class Program
    {
        public static void Main(string[] args)
        {
            new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config
                        .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                        .AddJsonFile("appsettings.json", true, true)
                        .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
                        .AddJsonFile("ocelot.json")
                        .AddEnvironmentVariables();
                })
                .ConfigureServices(s =>
                {
                    s.AddOcelot();
                })
                .UseIISIntegration()
                .Configure(app =>
                {
                    app.UseOcelot().Wait();
                })
                .Build()
                .Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }

Startup.cs:

public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {

            services.AddOcelot(Configuration);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

         //   await app.UseOcelot();

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

Я использую .NET Core 2.1 и пакет Ocelot NuGet версии 13.5.1.


person Stefan Voicila    schedule 28.11.2019    source источник
comment
По какому именно пути вы звоните через почтальона?   -  person tom redfern    schedule 28.11.2019
comment
Кроме того, почему вы используете агрегирование запросов?   -  person tom redfern    schedule 28.11.2019
comment
Путь для почтальона, который я использую: localhost: 61234 / BAD (61234 - порт для шлюза). Я использую агрегацию запросов, потому что мне нужны данные от обоих, и я не хочу использовать два запроса, в основном потому, что запросы находятся в разных микросервисах, а эти - в одном и используются просто как тест.   -  person Stefan Voicila    schedule 28.11.2019
comment
Вы получили разрешение на это?   -  person Simon Price    schedule 15.06.2020


Ответы (1)


Если вы используете агрегацию запросов, вам необходимо зарегистрировать реализацию IDefinedAggregator в Ocelot.

Нравиться:

public void ConfigureServices(IServiceCollection services)
{
    services.AddOcelot(Configuration).AddSingletonDefinedAggregator<FakeDefinedAggregator>();
}

иначе Ocelot не сможет найти ваш агрегатор в контейнере.

person tom redfern    schedule 28.11.2019
comment
Где написано, что это обязательно? - person Shad; 27.05.2021