偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

ASP.NET Core Api網(wǎng)關(guān)Ocelot初探

網(wǎng)絡(luò) 通信技術(shù)
Ocelot面向使用.NET運(yùn)行微型服務(wù)/面向服務(wù)的體系結(jié)構(gòu)的人員,這些體系結(jié)構(gòu)需要在系統(tǒng)中具有統(tǒng)一的入口點(diǎn)。特別是我想與IdentityServer參考和承載令牌輕松集成。Ocelot是按特定順序排列的一堆中間件。

[[387094]]

本文轉(zhuǎn)載自微信公眾號(hào)「UP技術(shù)控」,作者conan5566。轉(zhuǎn)載本文請(qǐng)聯(lián)系UP技術(shù)控公眾號(hào)。  

 概述

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

代碼實(shí)現(xiàn)

1、新建api客戶端1

2、新建api 網(wǎng)關(guān)test

3、nuget安裝Ocelot

4、Program文件添加ConfigureAppConfiguration

  1. public class Program 
  2.     { 
  3.         public static void Main(string[] args) 
  4.         { 
  5.             CreateHostBuilder(args).Build().Run(); 
  6.         } 
  7.  
  8.         public static IHostBuilder CreateHostBuilder(string[] args) => 
  9.             Host.CreateDefaultBuilder(args) 
  10.             .ConfigureAppConfiguration(conf => 
  11.             { 
  12.                 conf.AddJsonFile("ocelot.json"falsetrue); 
  13.             }) 
  14.                 .ConfigureWebHostDefaults(webBuilder => 
  15.                 { 
  16.                     webBuilder.UseStartup<Startup>(); 
  17.                 }); 
  18.     } 

5、Startup文件配置

  1. services.AddOcelot(Configuration); 
  2.  
  3. app.UseOcelot().Wait(); 

6、網(wǎng)關(guān)項(xiàng)目下添加文件ocelot.json

  1.   "ReRoutes": [ 
  2.     { 
  3.       "DownstreamPathTemplate""/api/WeatherForecast/GetList"
  4.       "DownstreamScheme""http"
  5.       "DownstreamHostAndPorts": [ 
  6.         { 
  7.           "Host""localhost"
  8.           "Port": 5000 
  9.         } 
  10.       ], 
  11.       "UpstreamPathTemplate""/GetList"
  12.       "UpstreamHttpMethod": [ "Get" ] 
  13.     }, 
  14.  
  15.     { 
  16.       "DownstreamPathTemplate""/{everything}"
  17.       "DownstreamScheme""http"
  18.       "DownstreamHostAndPorts": [ 
  19.         { 
  20.           "Host""localhost"
  21.           "Port": 5000 
  22.         } 
  23.       ], 
  24.       "UpstreamPathTemplate""/{everything}"
  25.       "UpstreamHttpMethod": [ "Post" ] 
  26.     }, 
  27.     { 
  28.       "DownstreamPathTemplate""/api/WeatherForecast/GetModel?id={s1}"
  29.       "DownstreamScheme""http"
  30.       "DownstreamHostAndPorts": [ 
  31.         { 
  32.           "Host""localhost"
  33.           "Port": 5000 
  34.         } 
  35.       ], 
  36.       "UpstreamPathTemplate""/GetModel?id={s1}"
  37.       "UpstreamHttpMethod": [ "Get" ] 
  38.     } 
  39.   ] 

7、2個(gè)項(xiàng)目運(yùn)行,測(cè)試

代碼地址

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

 

責(zé)任編輯:武曉燕 來(lái)源: UP技術(shù)控
相關(guān)推薦

2009-08-03 14:22:33

什么是ASP.NET

2021-01-13 07:33:41

API數(shù)據(jù)安全

2018-08-20 08:03:46

跨平臺(tái) Web操作系統(tǒng)

2024-09-09 07:37:51

AspJWT權(quán)限

2024-06-11 09:00:00

異步編程代碼

2025-01-15 00:01:00

開發(fā)應(yīng)用界面

2021-10-19 10:42:00

MVCAPI.NET

2021-02-19 06:54:33

配置系統(tǒng)ASP.NET Cor

2024-09-10 08:13:16

Asp項(xiàng)目輕量級(jí)

2024-07-02 08:45:08

2024-12-05 08:14:41

2010-03-10 09:35:18

ASP.NET緩存

2009-07-22 17:45:35

ASP.NET教程

2021-03-17 09:45:31

LazyCacheWindows

2021-02-06 21:40:13

SignalR通訊TypeScript

2021-02-02 16:19:08

Serilog日志框架

2021-11-01 14:52:38

ElasticSear索引SQL

2024-09-10 08:15:33

Asp項(xiàng)目API

2023-07-04 08:26:15

2009-07-28 17:17:19

ASP.NET概述
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)