NetCore Ocelot 之 Qos
Qos quality of service
Ocelot supports one Qos capability at the current time.You can set on a per Route basis if you want to use a circuit breaker when making requests to a downstream service. This uses an awesome .NET library called Polly.
The first thing you need to do fi you want to use the administration API is bring in the relevant NuGet package.
Then config in your configure service.
builder.Services.AddOcelot() //.AddCacheManager(c => c.WithDictionaryHandle())// cache manager .AddSingletonDefinedAggregator<CustomAdvancedAggregator>() .AddCustomLoadBalancer((serviceProvider, route, serviceDiscoveryProvider) => new CustomRandomLoadBalancer(serviceDiscoveryProvider.Get)) .AddConsul() .AddPolly();
The Qos configuration in ocelot.json
"QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10000, //ms
"TimeoutValue": 10000 //ms,default 90s
}
ExceptionAllowedBeforeBreaking - This value must set a numebr greater than 0 against ExceptionAllowedBeforeBreaking for this rule to be impletemented.
DurationOfBreak - This value specify the circuit breaker will stay open for 10 seconds after it is tripped.
TimeoutValue - This value specify if a request takes more than 10 seconds it will automatically be timed out.
You can set the TimeoutValue in isolation of the ExceptionAllowedBeforeBreaking and DurationOfBreak options.
"QoSOptions": {
"TimeoutValue":5000
}
If you do not add a Qos section Qos will not be used however Ocelot will default to a 90 seconds timeout on all downstream requests. If someone needs this to be configurabel open an issue.
Stop all api services e.g.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)