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.

 

posted @   云霄宇霁  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示