This article is a mirror article of machine translation, please click here to jump to the original article.

View: 47670|Reply: 5

[.NET Core] Ocelot Series (1) ASP.NET Core Gateway in practice

[Copy link]
Posted on 6/28/2020 6:50:12 PM | | | |
Ocelot is an open-source API gateway implemented in .NET Core, which is powerful and includes routing, request aggregation, service discovery, authentication, authentication, current limiting circuit breaker, and built-in load balancer integration with Service Fabric and Butterfly Tracing. These functions only need to be simple to complete, and we will explain the configuration of these functions one by one.

Of course, Java projects also have gateways, Spring Cloud Gateway is Spring Cloud's new gateway framework, previously Netflix Zuul.

Deploy Kong API Gateway on CentOS 7
https://www.itsvse.com/thread-5682-1-1.html

First, create an empty project ASP.NET Core 3.1 with the name: dotnet-gateway-demo

nuget installs ocelot with the following command:


Create two new asp.net Core 3.1 API projects, named web-api-demo1 and web-api-demo2, respectively. The solution structure is as follows:



Modify the Get method of the WeatherForecastController controller of the "web-api-demo1" and "web-api-demo2" projects with the following code:


demo1 link: http://localhost:7853/weatherforecast
Demo2 link: http://localhost:7863/weatherforecast



In the root directory of the dotnet-gateway-demo project, create a new configuration file "ocelot.json", as follows:

where the BaseUrl address is filled in with the launch URL of the current project,Fill in according to your actual situation

  • DownstreamPathTemplate: The relative path of the downstream service
  • DownstreamScheme: The downstream service http schema
  • DownstreamHostAndPorts: The address of the downstream service, if you use LoadBalancer, you can fill in multiple fields here
  • UpstreamPathTemplate: 上游也就是用户输入的请求Url模板
  • UpstreamHttpMethod: 上游请求http方法,可使用数组


Join in Program.cs's CreateHostBuilder

Edit the Startup.cs file with the following code:

Its main codes are:

Set up a startup project and start 3 web projects at the same time, as shown in the following figure:



Once the setup is complete, launch and, according to our configuration rules, try to access:The hyperlink login is visible.andThe hyperlink login is visible.As shown below:


We add the following configuration to the ocelot.json file, try to reverse proxy this site, the configuration is as follows:

Try to visit:The hyperlink login is visible.



Source code download:

Tourists, if you want to see the hidden content of this post, pleaseReply


Reference Documentation:The hyperlink login is visible.

(End)






Previous:VS 2019 (Visual Studio) code cleanup
Next:[Front-end must-have] developer debugging panel
Posted on 6/28/2020 9:23:39 PM |
The article is good...
Posted on 6/29/2020 9:22:46 AM |
mark mark
Posted on 11/30/2020 9:45:20 PM |
Microservices, microservices, microservices, microservices, and microservices
Posted on 6/24/2021 4:41:12 PM |
Code not viewable?
Posted on 5/16/2023 11:16:05 AM |
Ocelot Series (1) ASP.NET Core Gateway in practice
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com