ocelot+consul的配置问题
1.在使用
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddOcelot(Configuration)
.AddConsul()
.AddConfigStoredInConsul()
.AddPolly();
}
该方法一旦使用AddConfigStoredInConsul(),启动项目之后页面就会报错500,内部服务错误。如果不使用该方法并且reroute的下游服务使用ip和端口的明文配置,那么可以正常请求
2.我在consul中添加了一个name为TestApiServer的服务,并在ocelot中使用如下配置
{
"UseServiceDiscovery": true, // use Consul service discovery
"DownstreamPathTemplate": "/api/{url}",
"DownstreamScheme": "http",
"ServiceName": "TestApiServer",
"LoadBalancerOptions": {
"Type": "RoundRobin"
},
"UpstreamPathTemplate": "/TestApiServer/{url}",
"UpstreamHttpMethod": [ "Get", "Post" ],
"RateLimitOptions": {
"ClientWhitelist": [ "admin" ], // 白名单
"EnableRateLimiting": true, // 是否启用限流
"Period": "1m", // 统计时间段:1s, 5m, 1h, 1d
"PeriodTimespan": 15, // 多少秒之后客户端可以重试
"Limit": 10 // 在统计时间段内允许的最大请求数量
}
}
当我发起请求为http://192.168.22.122:8000/TestApiServer/values时,ocelot找不到对应的服务对我的请求进行转发。各位大佬有空的话进来帮忙看看