一、 Ocelot 基本配置
Ocelot 就是一个提供了请求路由、安全验证等功能的 API 网关微服务。
建一个空的 asp.net core web的apiAPI 网关项目:OcelotTest(我选择的是2.1版本的API做测试)添加包:Install-Package Ocelot
项目根目录下创建 configuration.json 创建之后右键属性改成:如果较新则复制
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/api/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
],
"UpstreamPathTemplate": "/MsgService/{url}",//MsgService表示一个netcore web的一个api项目名称
"UpstreamHttpMethod": [ "Get", "Post" ]
},
{
"DownstreamPathTemplate": "/api/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [