如何解决如何在 Ocelot API Gateway 中聚合请求?
我有以下两个端点: 本地主机:5001/api/packages?storeid={id} 本地主机:5002/api/stores/{id}
如何使用 Ocelot API Gateway 聚合它们?
我目前有这个:
{
"RouteKeys": [
"Business","Packages"
],"UpstreamPathTemplate": "/test"
}
],
但我不知道当有 1 个端点使用 '/{id}' 而另一个端点使用 '?store={id}' 时它是如何工作的
以下是我的完整 Ocelot 配置:
//Routing
"Routes": [
//Packages API with downroute
{
"DownstreamPathTemplate": "/api/Packages/{everything}","DownstreamScheme": "https","DownstreamHostAndPorts": [
{
"Host": "localhost","Port": "5001"
}
],"UpstreamPathTemplate": "/api/Packages/{everything}","Key": "PackagesDownroute"
},//Packages API
{
"DownstreamPathTemplate": "/api/Packages","UpstreamPathTemplate": "/api/Packages","Key": "Packages"
},//Orders API
{
"DownstreamPathTemplate": "/apI/Orders/{everything}","Port": "5002"
}
],"UpstreamPathTemplate": "/apI/Orders/{everything}"
},//Business API with downroute
{
"DownstreamPathTemplate": "/api/Business/{everything}","Port": "5003"
}
],"UpstreamPathTemplate": "/api/Business/{everything}","Key": "BusinessDownroute"
},//Business API
{
"DownstreamPathTemplate": "/api/Business","UpstreamPathTemplate": "/api/Business","Key": "Business"
}
],"Aggregates": [
{
"RouteKeys": [
"BusinessDownroute",//GLOBAL CONfig
"GlobalConfiguration": {
"BaseUrl": "https://localhost:4999"
}
}
解决方法
我使用相似的 id 解决了这个问题,不能使用不同的名称端点或不同的 id
first endpoint : http://localhost:5002/Orders/123456
second endpoint : http://localhost:5003/api/Business/123456
{
"DownstreamPathTemplate": "/api/Orders/{everything}","DownstreamScheme": "http","DownstreamHostAndPorts": [
{
"Host": "localhost","Port": "5002"
}
],"UpstreamPathTemplate": "/Orders/{everything}","UpstreamHttpMethod": [ "GET" ],"key": "OrdersId"
},{
"DownstreamPathTemplate": "/api/Business/{everything}","Port": "5003"
}
],"UpstreamPathTemplate": "/Business/{everything}","key": "BusinessId"
}],"Aggregates": [
{
"RouteKeys": [ "OrdersId","BusinessId" ],"UpstreamPathTemplate": "/ExampleMultipleEndpoint/v1/{everything}"
}
]
这是一个响应示例
{
"OrdersId": {
//
},"BusinessId": {
//
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。