【问题标题】:Ocelot API gateway setting only TimeOut value throwing errorOcelot API 网关仅设置 TimeOut 值抛出错误
【发布时间】:2020-11-07 15:36:36
【问题描述】:

根据Ocelot文档Quality Of Service我们只能在Routes中提到TimeOutValue,比如

"QoSOptions": {
    "TimeoutValue":5000
}

但这会抛出异常

Ocelot.Requester.Middleware.HttpRequesterMiddleware: Debug: requestId: 800002b3-0002-fd00-b63f-84710c7967bb, previousRequestId: no previous request id, message: IHttpRequester returned an error, setting pipeline error
Ocelot.Responder.Middleware.ResponderMiddleware: Warning: requestId: 800002b3-0002-fd00-b63f-84710c7967bb, previousRequestId: no previous request id, message: Error Code: UnableToCompleteRequestError Message: Error making http request, exception: System.ArgumentException: The enumerable of policies to form the wrap must contain at least two policies. (Parameter 'policies')
   at Polly.Policy.WrapAsync(IAsyncPolicy[] policies)
   at Ocelot.Provider.Polly.PollyCircuitBreakingDelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Ocelot.Requester.HttpClientHttpRequester.GetResponse(HttpContext httpContext) errors found in ResponderMiddleware. Setting error response for request path:/api/v1/cust/clients, request method: GET
Ocelot.Errors.Middleware.ExceptionHandlerMiddleware: Debug: requestId: 800002b3-0002-fd00-b63f-84710c7967bb, previousRequestId: no previous request id, message: ocelot pipeline finished
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 200.2779ms 500 

我的路线配置是

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/{version}/cust/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5001
        }
      ],
      "UpstreamPathTemplate": "/api/{version}/cust/{everything}",
      "UpstreamHttpMethod": [],
      "QoSOptions": {
        "TimeoutValue": 900000
      }
    }
  ],
  "GlobalConfiguration": {
    "RequestIdKey": "OcRequestId",
    "AdministrationPath": "/administration"
  }
}

我的 .Net Core 版本是 3.1,Ocelet 版本是 16.0.1

【问题讨论】:

标签: asp.net-core api-gateway ocelot


【解决方案1】:

只有一个策略(超时策略)可能会出现一些问题。

我必须添加断路器设置才能使这项工作:

 "QoSOptions": {
    "ExceptionsAllowedBeforeBreaking":99999,
    "DurationOfBreak":0,
    "TimeoutValue":5000
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2020-10-20
    • 2019-09-24
    • 2019-09-30
    • 2021-12-11
    • 2019-02-21
    • 1970-01-01
    • 2021-02-25
    相关资源
    最近更新 更多