目录概述 代码实现 1、新建api客户端12、新建api 网关test3、nuget安装Ocelot4、Program文件添加ConfigureAppConfigurati
Ocelot面向使用.net运行微型服务/面向服务的体系结构的人员,这些体系结构需要在系统中具有统一的入口点。特别是我想与IdentityServer参考和承载令牌轻松集成。Ocelot是按特定顺序排列的一堆中间件。Ocelot将HttpRequest对象操作到由其配置指定的状态,直到到达请求构建器中间件,在该中间件中它创建一个HttpRequestMessage对象,该对象用于向下游服务发出请求。发出请求的中间件是Ocelot管道中的最后一件事。它不会调用下一个中间件。有一块中间件可将HttpResponseMessage映射到HttpResponse对象,然后将其返回给客户端。基本上,它具有许多其他功能。
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>();
});
}
services.AddOcelot(Configuration);
app.UseOcelot().Wait();
{
"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" ]
}
]
}
https://gitee.com/conanOpenSource_admin/Example/commit/b3b5a6b15a060b46c5ecd2ea31f0d36791cda18c
以上就是ASP.net core Api网关Ocelot的使用初探的详细内容,更多关于ASP.net core Api网关Ocelot的资料请关注编程网其它相关文章!
--结束END--
本文标题: ASP.NET Core Api网关Ocelot的使用初探
本文链接: https://www.lsjlt.com/news/121545.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2023-05-21
2023-05-21
2023-05-21
2023-05-21
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0