Ocelot Rerouting is not working properly with .Net Core 3.1

Created on 20 Jan 2020  路  9Comments  路  Source: ThreeMammals/Ocelot

Hi Team,

I building API with Ocelot microservices. Unfortunately, I'm facing a problem with rerouting. I've created 3 projects[API Gateway, Products, and Customers] based on the attached reference URL [https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core-part-two/].

On parallel Run the 3 projects. Now I can get the response of customers and products but the API gateway page looks like [This localhost page can鈥檛 be found with 404 status]. But when I rewrite the API call in the API gateway URL at that time also it's not working as expected. Kindly help me to resolve this issue why the rerouting is not working

+Attached the codes

configuration.txt
Program.txt
StartUp.txt

  • Version: VS 2019 Core 3.1
  • Platform: Windows
question waiting

Most helpful comment

Hey all so it seems it鈥檚 not an Ocelot issue it鈥檚 within the config, ReRoutes has been renamed to Routes in version 16.*.+ so that鈥檚 why our routing doesn鈥檛 work properly.

I can confirm I downgraded to 15 and it worked but then after reading I changed it back to 16 and changed ReRoutes in my config to be Routes and it worked

All 9 comments

I think I see a couple of potential problems with your code that could cause it not to work:

  • You construct your configuration inside of the constructor of your Startup class, but you only put the configuration into the Configuration property on that class. It never gets added to the dependency injection container, so Ocelot can't read it. Have a look through configuration docs for ASP.NET Core 3.1 to setup the configuration properly.
  • The Configure method on the Startup class is async void. I don't think that is supported in ASP.NET Core. You can try removing the async modifier and using app.UseOcelot().Wait() as described in the documentation.

Let me know how that goes.

I am also facing a similar issue. I was able to create my microservice successfully. Created an API gateway using Ocelot. Though, my web api is running and getting accessed without any issues, am unable to reroute to them using the gateway. Can you please guide me ? I am new to microservices and Ocelot API Gateway. Attaching the following files.

  1. ocelot.json
  2. Startup.cs and Program.cs ( api gateway)
    Startup.txt
    Program.txt

ocelot.txt

Well. I could fix it. I installed an older version of Ocelot API Gateway for my solution that is in ASP.NET Core 3.1. It started working. Thank you.

Hi i'm getting the same problem, solution works in .net core 2.2 with ocelot 13.5 but I spent 6 hours trying to get it to work in .net core 3.1, which version of Ocelot did you use?

I had the same problem. I had installed latest Ocelot version (16.0.1), which didn't work.
This was fixed when I downgraded my Ocelot version to 15.0.6. My .NET Core version is still 3.1.
I'm not sure if other versions between 15.0.6 might work, as I downgraded the version to this specific version because of another project I looked at.

It seems to me that at least something in the latest Ocelot version is broken.

Hey all so it seems it鈥檚 not an Ocelot issue it鈥檚 within the config, ReRoutes has been renamed to Routes in version 16.*.+ so that鈥檚 why our routing doesn鈥檛 work properly.

I can confirm I downgraded to 15 and it worked but then after reading I changed it back to 16 and changed ReRoutes in my config to be Routes and it worked

Thanks @akashbakshi :) Changing from ReRoutes to Routes solves the problem.

These are terrible, the framework simply changes the element name in Json.

For Ocelot: v16.0.1
1: "ReRoutes": Changed to "Routes" : [
2: "DownstreamHostsAndPorts" Changed to ""DownstreamHostAndPorts"
3: In "DownstreamHostAndPorts" Hosts changed to Host

Hello.

Ocelot.{Environment}.json files need to be updated in order to work with v.16.+.

Simply update all ReRoute sub-strings to Route.

Details can be found here: https://github.com/ThreeMammals/Ocelot/commit/3439be89271bb37b170429d69ca74978c941432e#diff-f7f837f4fb4071b7bebdc5c611229011

Was this page helpful?
0 / 5 - 0 ratings