首页 > 其他分享 >NetCore Ocelot 之 Qos

NetCore Ocelot 之 Qos

时间:2023-10-08 19:15:31浏览次数:35  
标签:set Qos NetCore will Ocelot TimeoutValue ExceptionAllowedBeforeBreaking

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.

 

标签:set,Qos,NetCore,will,Ocelot,TimeoutValue,ExceptionAllowedBeforeBreaking
From: https://www.cnblogs.com/qindy/p/17749884.html

相关文章

  • NetCore Ocelot 之 Load Balancer
    OcelotcanloadbalanceacrossavailabledownstreamservicesforeachRoute.ThismeansyoucanscaleyourdownstreamservicesandOcelotcanusethemeffectively.TheTypeofloadbalanceravailbleare:  LeastConnection -trackswhichservicearedeal......
  • QOS中的traffic-policy
    流程1、感应兴趣流,禁止vlan10访问vlan20aclnumber3000rule5denyipsource10.1.1.00.0.0.255destination20.1.1.00.0.0.2552、定义流分类trafficclassifierc1operatororif-matchacl30003、定义流行为trafficbehaviorb1permit4、绑定流分类、流行为traffi......
  • NetCore Ocelot 之 Authentication
    InordertoauthenticateRoutesandsubsequentlyuseanyofOcelot'sclaimsbasedfeaturessuchasauthorizationormodifyingtherequestwithvaluesfromthetoken.UsersmustregisterauthenticationservicesintheirStartup.csasusualbuttheypr......
  • NetCore Ocelot 之 Rate Limiting
    Ocelotsupportsratelimitingofupstreamrequestssothatyourdownstreamservicesdonotbecomeoverloaded.OKsotogetratelimitingworkingforaRouteyouneedtoaddthefollowingjsontoit."RateLimitOptions":{"ClientWhi......
  • NetCore学习笔记:单元测试和集成测试
    前言#我在使用AspNetCore的这段时间内,看了很多开源项目和博客,发现各种.Net体系的新技术很多人都有关注和使用,但却很少有人关注测试。测试是软件生命周期中的一个非常重要的阶段,对于保证软件的可靠性具有极其重要的意义。在应用程序的开发过程中,为了确保它的功能与预期一致,......
  • 开源.NetCore通用工具库Xmtool使用连载 - 扩展动态对象篇
    【Github源码】《上一篇》介绍了Xmtool工具库中的图形验证码类库,今天我们继续为大家介绍其中的扩展动态对象类库。<br>扩展动态对象是整个工具库中最重要的一个设计。在软件开发过程中,我们经常需要定义各种各样的数据对象;例如:用于参数传递的数据实体类、用于接口返回结果的Json......
  • AspNetCore不明确的匹配异常-请求与多个终结点匹配
    框架:net6.0AspNetCoreMVC添加区域控制器HomeController,直接启动报错;因默认路由下存在相同的控制器HomeController(非区域的),需要修改路由映射配置;在Program.cs添加区域路由配置app.MapAreaControllerRoute(name:"areaRoute",areaName:"Admin",pattern:......
  • .netCore 图形验证码,非System.Drawing.Common
    netcore需要跨平台,说白点就是放在windows服务器要能用,放在linux服务器上也能用,甚至macos上。很多时候需要使用到图形验证码,这就有问题了。旧方案1.引入包<PackageReferenceInclude="System.Drawing.Common"Version="5.0.3"/>2.添加引用usingSystem.Drawing;usingSystem......
  • NetCore 国际化最佳实践
    NetCore国际化最佳实践ASP.NETCore中提供了一些本地化服务和中间件,可将网站本地化为不同的语言文化。ASP.NETCore中我们可以使用Microsoft.AspNetCore.Localization库来实现本地化。但是默认只支持使用资源文件方式做多语言存储,很难在实际场景中使用。有没有可能支持官方资源......
  • netcore请求json斜杠带空格导致请求报错
    我用netcore发布了一个webapi接口,个别电脑,同样的浏览器(谷歌),swagger调用接口的时候,它的json体会加空格,然后请求就会报错。这是控制器里的方法下图是请求输入: 下图是加了空格的请求内容,如红色框所示,带了空格 下图是报错的内容下图是正常请求的内容,可以返回想要的结果......