首页 > 解决方案 > 当出现 n 个异常时,Ocelot QoS 不会断路

问题描述

我正在Ocelot Gateway上执行 PoC以用于我们的微服务架构。到目前为止,我已成功使用网关执行所有路由任务。

它提供了一个 QoS 服务,该服务在 ocelot.json 中为断路器保存配置,并在一段时间内断开电路。

我的ocelot.json文件中针对特定路由设置的配置如下:

{
      "DownstreamPathTemplate": "/api/classes/exception/{id}",
      "DownstreamScheme": "http",
      "UpstreamPathTemplate": "/classes/exception/{id}",
      "ServiceName": "class-service",
      "UpstreamHttpMethod": [ "Get" ],
      "LoadBalancerOptions": {
        "Type": "LeastConnection"
      },
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 2,
        "DurationOfBreak": 10000,
        "TimeoutValue": 3000
      }
    }

现在,这适用于超时问题,当路由在 3 秒内没有响应时,它会中断电路 10 秒。

但是对于异常情况,在调用路由时,出现2次异常时,不会断路。

是否需要更多配置?

为 Ocelot 和 Ocelot.Provider.Polly 添加了 Nuget 包,并在我的Startup.cs文件中添加了以下内容:

 s.AddOcelot().AddPolly();

请帮我解决这个问题。我已经按照 [Ocelot 文档] https://ocelot.readthedocs.io/en/latest/features/qualityofservice.html来实现这个

标签: microservicescircuitocelot

解决方案


推荐阅读