1

I'm trying Ocelot package in NET6 Framework but unfortunately, it does not "try" the second Host when the first is unavailable. Example:

"Routes": [
{
  "UpstreamPathTemplate": "/api/abc",
  "UpstreamHttpMethod": [ "POST" ],
  "QoSOptions": {
    "ExceptionsAllowedBeforeBreaking": 2,
    "DurationOfBreak": 5000,
    "TimeoutValue": 2000
  },
    "DownstreamPathTemplate": "/api/qwe",
    "DownstreamScheme": "http",
    "DownstreamHostAndPorts": [
      {
        "Host": "serverA",
        "Port": 2019
      },
      {
        "Host": "serverB",
        "Port": 2019
      }
    ],
    "LoadBalancerOptions": {
      "Type": "RoundRobin"
    }

So when the ServerA service is offline I do get httpstatus 502 "No connection could be made because the target machine actively refused it" but I was hoping Ocelot would try automatically the ServerB.

Do I need to configure something else on Ocelot to have this behaviour?

Thanks a lot.

Tiago
  • 45
  • 5

1 Answers1

0

Can you try this ?

 var conf = new OcelotPipelineConfiguration()
                {
                    PreErrorResponderMiddleware = async (ctx, next) =>
                    {
                        if (ctx.HttpContext.Request.Path.Equals(new PathString("/")))
                        {
                            await ctx.HttpContext.Response.WriteAsync("ok");
                        }
                        else
                        {
                            await next.Invoke();
                        }
                    }
                };
                app.UseOcelot(conf).Wait();
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34745770) – Cody Duong Jul 30 '23 at 06:06