question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ocelot aggregate interceptor

See original GitHub issue

New Feature

Motivation for New Feature

Let say, I have 2 micro services, called as CustomerMicroService and OrderMicroService CustomerMicroService is in charge of managing customer information. OrderMicroService manages orders that a customer has made.

Let me talk about 2 api end-point from Customer micro-service and Order micro service first.

api/customer/search

  • Request:
{
	"pagination": {
		"page": 1,
		"records": 30
	}
}

-> Get the first 30 customers from Customer micro service.

  • Response:
{
	"records": [
		.. list of customers
	]
	"total": 30
}

-> Returns a list of customers with total number of customer that match the search condition.

api/order/search

  • Request:
{
	"customerIds": [1, 2, 3, 4, 5],
	"status": ["pending", "active"]
}

-> Get list of order base on the previous loaded customer from the above api.

  • Response:
{
	"records": [
		.. list of orders
	]
	"total": 300
}

-> Returns a list of orders that match the search condition.

Steps to Reproduce the Problem

Now, my API Gateway uses Ocelot to aggregate 2 api endpoint api/customer/search and api/order/search into one API for mobile & web to be consumed, let call it api/gateway/load-customer-orders/{customerId}

This is my ocelot.json:

{
  "Aggregates": [
    {
      "ReRouteKeys": [
        "Customer",
        "Order"
      ],
      "UpstreamPathTemplate": "api/gateway/load-customer-orders/{customerId}",
      "Aggregator": "LoadCustomerOrdersAggregator"
    }
  ],
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/customer/search",
      "DownstreamScheme": "http",
      "UpstreamPathTemplate": "/api/customer/search",
      "UpstreamHttpMethod": [ "POST" ],
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 62744
        }
      ],
      "Key": "Customer"
    },
    {
      "DownstreamPathTemplate": "/api/order/search",
      "DownstreamScheme": "http",
      "UpstreamPathTemplate": "/api/order/search",
      "UpstreamHttpMethod": [ "GET" ],
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 62724
        }
      ],
      "Key": "Order"
    }
  ]
}

My LoadCustomerOrdersAggregator.cs:

public class LoadCustomerOrdersAggregator : IDefinedAggregator
    {
        #region Methods

        /// <summary>
        /// Load customer orders.
        /// </summary>
        /// <param name="responses"></param>
        /// <returns></returns>
        public virtual async Task<DownstreamResponse> Aggregate(List<DownstreamResponse> responses)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

As far as I know Ocelot only support GET method. It is Ok for me, for now, since I just pass {customerId} into my aggregate api api/gateway/load-customer-order/{customerId}.

But it would be nice if I can get the information of Dictionary<string, DownStreamRequest> in aggregate class to manually handle the data by my self.

The aggregate class implemenation should be :

  public virtual async Task<DownstreamResponse> Aggregate(Dictionary<string, DownstreamRequest> requests, List<DownstreamResponse> responses)
        {
            // Base on the request dictionary to manually handle HttpClient call.
            throw new NotImplementedException();
        }

Specifications

  • Version: 13.0.0
  • Platform: Windows
  • Subsystem:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
redplanecommented, Feb 12, 2019

Thank you for you reply. I’m waiting for that release, coz my project needs that function 😃

0reactions
redplanecommented, Feb 21, 2019

Any updates ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request Aggregation — Ocelot 1.0.0 documentation
Request Aggregation¶. Ocelot allows you to specify Aggregate Routes that compose multiple normal Routes and map their responses into one object.
Read more >
Routing — Ocelot 1.0.0 documentation
Ocelot's describes the routing of one request to another as a Route. In order to get anything working in Ocelot you need to...
Read more >
Building API Gateway on .NET with Ocelot - Alberto Moreno
Request aggregation in API gateways with Ocelot; Authentication to API ... It can be used to intercept any request and perform validation, ...
Read more >
Building .NET Core API Gateway with Ocelot | by Thanh Le
Ocelot is an open-source API Gateway built on ASP. ... Routing; Request Aggregation; Service Discovery with Consul & Eureka; Service Fabric ...
Read more >
Ocelot API Gateway: Routing & Aggregation & Authentication
Ocelot Api Gateway aracılığıyla Routing, Request Aggregation, Authentication ... Intercept edeceğimizi RequestLogger sınıfıyla bildiriyoruz.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found