-
Notifications
You must be signed in to change notification settings - Fork 22
Ocelot
L edited this page Apr 21, 2021
·
5 revisions
上游:服务消费方(eg.MVC Server, SPA App)的调用配置,进来的请求
下游:提供API服务的配置,跳转的实际请求地址
{
"ReRoutes": [
{
//Upstream表示上游请求,即客户端请求到API Gateway的请求
"UpstreamPathTemplate": "/Service1/{url}", //请求路径模板
"UpstreamHttpMethod": [ "Get", "Post" ], //请求方法数组
"UseServiceDiscovery": false, //启用服务发现
//Downstream表示下游请求,即API Gateway转发的目标服务地址
"DownstreamPathTemplate": "/api/{url}", //下游请求地址模板
"DownstreamScheme": "http", //请求协议,目前应该是支持http和https
//A***************指定单个转发地址
"DownstreamHostAndPorts": [ //请求服务地址
{
"Host": "localhost",
"Port": 7001
}
]
}
]
}
UpstreamPathTemplate:上游
DownstreamPathTemplate:下游
DownstreamHostAndPorts:下游服务地址
UpstreamHttpMethod:允许的请求方法(GET、POST、PUT、DELETE)
配置添加:
"GlobalConfiguration": {
//"BaseUrl": "https://api.mybusiness.com"
"ServiceDiscoveryProvider": {
"Host": "192.168.80.100", // Consul Service IP
"Port": 8500 // Consul Service Port
}
}
BaseUrl:Ocelot外部暴露的Url
ServiceDiscoveryProvider:Consul的IP和端口号
同时去掉ReRoutes
节点里面单独配置的DownstreamHostAndPorts
Ocelot的使用(基本使用)
.NET Core微服务之基于Ocelot实现API网关服务
.NET Core微服务之基于Ocelot实现API网关服务(续)
ocelot官方文档