Asp.net core Ocelot路由聚合:不存在或没有正确的ServiceName属性
我试图用Ocelot创建一个概念验证,并研究API聚合 我的Ocelot配置看起来有点像这样Asp.net core Ocelot路由聚合:不存在或没有正确的ServiceName属性,asp.net-core,.net-core,ocelot,Asp.net Core,.net Core,Ocelot,我试图用Ocelot创建一个概念验证,并研究API聚合 我的Ocelot配置看起来有点像这样 { "Routes": [ { "DownstreamPathTemplate": "/api/fee/calculator", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ { "Host": "localhost", "Por
{
"Routes": [
{
"DownstreamPathTemplate": "/api/fee/calculator",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
}
],
"UpstreamPathTemplate": "/fee/calculator",
"UpstreamHttpMethod": ["GET", "POST"],
"Key": "FeeCalculator",
"FileCacheOptions": {
"TtlSeconds": 600, // Time to Live
"Region": "fee-calc" // Cache name
}
},
{
"DownstreamPathTemplate": "/api/form/getlexicon",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
],
"UpstreamPathTemplate": "/form/getlexicon",
"UpstreamHttpMethod": ["GET", "POST"],
"Key": "FormEngine",
"RateLimitOptions": {
"ClientWhitelist": [], // array of clients not effected by rate limiting
"EnableRateLimiting": true,
"Period": "1m", // time period limit applies for e.g. 1s, 1m, 1h, 1d etc
"PeriodTimespan": 60, // retry after certain number of seconds
"Limit": 5 // number of requests in given period
//"QuotaExceededMessage" custom message to client for quota exceeded
//"HttpStatusCode" custom http status code
},
"FileCacheOptions": {
"TtlSeconds": 600,
"Region": "form-engine"
}
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:4001",
"RequestIdKey": "OcRequestId"
},
"Aggregates": [
{
"RouteKeys": [
"FormEngine",
"FeeCalculator"
],
"UpstreamPathTemplate": "/FormAndFeeCalculation",
"Aggregator": "FakeDefinedAggregator"
}
]
}
我已删除不属于此问题的路线
我的Startup.cs有这个
services.AddOcelot(Configuration)
.AddTransientDefinedAggregator<FakeDefinedAggregator>()
.AddCacheManager(configCacheBuilder =>
{
configCacheBuilder.WithDictionaryHandle();
});
services.AddOcelot(配置)
.AddTransientDefinedAggregator()
.AddCacheManager(configCacheBuilder=>
{
configCacheBuilder.WithDictionaryHandle();
});
然后我需要为FakeDefinedAggregator创建类,如下所示
public class FakeDefinedAggregator : IDefinedAggregator
{
public async Task<DownstreamResponse> Aggregate(List<HttpContext> responses)
{
var contentBuilder = new StringBuilder();
contentBuilder.Append(responses);
var stringContent = new StringContent(contentBuilder.ToString())
{
Headers = { ContentType = new MediaTypeHeaderValue("application/json") }
};
return new DownstreamResponse(stringContent, HttpStatusCode.OK, new List<KeyValuePair<string, IEnumerable<string>>>(), "OK");
}
}
公共类伪造定义聚合器:IDefinedAggregator
{
公共异步任务聚合(列表响应)
{
var contentBuilder=new StringBuilder();
contentBuilder.Append(响应);
var stringContent=new stringContent(contentBuilder.ToString())
{
Headers={ContentType=new MediaTypeHeaderValue(“应用程序/json”)}
};
返回新的下行响应(stringContent,HttpStatusCode.OK,new List(),“OK”);
}
}
运行\调试应用程序时,我会在app.UseOcelot().Wait()处收到此错误代码>
异常:无法启动Ocelot,错误为:aggregateRoute/FormEngineAndFeeCalculation的路由不存在或没有正确的ServiceName属性
在此问题上的任何协助都将不胜感激 您的路线有GET和POST方法:
"UpstreamHttpMethod": ["GET", "POST"],
文件上说,