欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET Core Api網關Ocelot的使用初探

 更新時間:2021年03月12日 11:12:03   作者:UP技術控  
這篇文章主要介紹了ASP.NET Core Api網關Ocelot的使用初探,幫助大家更好的理解和學習使用.NET技術,感興趣的朋友可以了解下

概述

Ocelot面向使用.NET運行微型服務/面向服務的體系結構的人員,這些體系結構需要在系統(tǒng)中具有統(tǒng)一的入口點。特別是我想與IdentityServer參考和承載令牌輕松集成。Ocelot是按特定順序排列的一堆中間件。Ocelot將HttpRequest對象操作到由其配置指定的狀態(tài),直到到達請求構建器中間件,在該中間件中它創(chuàng)建一個HttpRequestMessage對象,該對象用于向下游服務發(fā)出請求。發(fā)出請求的中間件是Ocelot管道中的最后一件事。它不會調用下一個中間件。有一塊中間件可將HttpResponseMessage映射到HttpResponse對象,然后將其返回給客戶端?;旧?,它具有許多其他功能。

代碼實現

1、新建api客戶端1

2、新建api 網關test

3、nuget安裝Ocelot

4、Program文件添加ConfigureAppConfiguration

public class Program
 {
  public static void Main(string[] args)
  {
   CreateHostBuilder(args).Build().Run();
  }

  public static IHostBuilder CreateHostBuilder(string[] args) =>
   Host.CreateDefaultBuilder(args)
   .ConfigureAppConfiguration(conf =>
   {
    conf.AddJsonFile("ocelot.json", false, true);
   })
    .ConfigureWebHostDefaults(webBuilder =>
    {
     webBuilder.UseStartup<Startup>();
    });
 }

5、Startup文件配置

 services.AddOcelot(Configuration);
 app.UseOcelot().Wait();

6、網關項目下添加文件ocelot.json

{
 "ReRoutes": [
 {
  "DownstreamPathTemplate": "/api/WeatherForecast/GetList",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
  {
   "Host": "localhost",
   "Port": 5000
  }
  ],
  "UpstreamPathTemplate": "/GetList",
  "UpstreamHttpMethod": [ "Get" ]
 },

 {
  "DownstreamPathTemplate": "/{everything}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
  {
   "Host": "localhost",
   "Port": 5000
  }
  ],
  "UpstreamPathTemplate": "/{everything}",
  "UpstreamHttpMethod": [ "Post" ]
 },
 {
  "DownstreamPathTemplate": "/api/WeatherForecast/GetModel?id={s1}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
  {
   "Host": "localhost",
   "Port": 5000
  }
  ],
  "UpstreamPathTemplate": "/GetModel?id={s1}",
  "UpstreamHttpMethod": [ "Get" ]
 }
 ]
}

7、2個項目運行,測試

代碼地址

https://gitee.com/conanOpenSource_admin/Example/commit/b3b5a6b15a060b46c5ecd2ea31f0d36791cda18c

以上就是ASP.NET Core Api網關Ocelot的使用初探的詳細內容,更多關于ASP.NET Core Api網關Ocelot的資料請關注腳本之家其它相關文章!

相關文章

最新評論