Simon Price
Simon Price

Reputation: 3261

Ocelot Route Aggregation : either do not exist or do not have correct ServiceName property

I am trying to create a proof of concept with Ocelot and looking at API Aggregation.

My Ocelot config looks a little like this

  {
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/fee/calculator",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 7001
        }
      ],
      "UpstreamPathTemplate": "/fee/calculator",
      "UpstreamHttpMethod": ["GET", "POST"],
      "Key": "FeeCalculator",
      "FileCacheOptions": {
        "TtlSeconds": 600, // Time to Live
        "Region": "fee-calc" // Cache name
      }
    },
    {
      "DownstreamPathTemplate": "/api/form/getlexicon",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5001
        }
      ],
      "UpstreamPathTemplate": "/form/getlexicon",
      "UpstreamHttpMethod": ["GET", "POST"],
      "Key": "FormEngine",
      "RateLimitOptions": {
        "ClientWhitelist": [], // array of clients not effected by rate limiting
        "EnableRateLimiting": true,
        "Period": "1m", // time period limit applies for e.g. 1s, 1m, 1h, 1d etc 
        "PeriodTimespan": 60, // retry after certain number of seconds
        "Limit": 5 // number of requests in given period
        //"QuotaExceededMessage" custom message to client for quota exceeded
        //"HttpStatusCode" custom http status code
      },
      "FileCacheOptions": {
        "TtlSeconds": 600,
        "Region": "form-engine"
      }

    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "https://localhost:4001",
    "RequestIdKey": "OcRequestId"
  },
  "Aggregates": [
    {
      "RouteKeys": [
        "FormEngine",
        "FeeCalculator"
      ],
      "UpstreamPathTemplate": "/FormAndFeeCalculation",
      "Aggregator": "FakeDefinedAggregator"
    }
  ]
}

I have remove routes where they are not part of this issue

My Startup.cs has this

services.AddOcelot(Configuration)
            .AddTransientDefinedAggregator<FakeDefinedAggregator>()
            .AddCacheManager(configCacheBuilder =>
            {
                configCacheBuilder.WithDictionaryHandle();
            });

I then needed to create the class for FakeDefinedAggregator which is like so

public class FakeDefinedAggregator : IDefinedAggregator
{
    public async Task<DownstreamResponse> Aggregate(List<HttpContext> responses)
    {
        var contentBuilder = new StringBuilder();
        contentBuilder.Append(responses);

        var stringContent = new StringContent(contentBuilder.ToString())
        {
            Headers = { ContentType = new MediaTypeHeaderValue("application/json") }
        };

        return new DownstreamResponse(stringContent, HttpStatusCode.OK, new List<KeyValuePair<string, IEnumerable<string>>>(), "OK");

    }
}

When running \ debugging the application I then get this error at app.UseOcelot().Wait();

Exception: Unable to start Ocelot, errors are: Routes for aggregateRoute /FormEngineAndFeeCalculation either do not exist or do not have correct ServiceName property

Any assistance on this matter will be gratefully received.

Upvotes: 2

Views: 2681

Answers (1)

Igor
Igor

Reputation: 2369

your routes have GET and POST methods:

"UpstreamHttpMethod": ["GET", "POST"],

documentation says that Aggregation only supports the GET HTTP Verb.

Upvotes: 2

Related Questions