Spring-cloud-netflix: Zuul Filter for request splitting & result aggregation

Created on 12 May 2016  路  12Comments  路  Source: spring-cloud/spring-cloud-netflix

Is there a way to create a zuul filter in which I can rout one incoming request to two or more backend services and do a result aggregation as a Map or anything else?

I think of something like a rout filter to implement a backends-for-frontends pattern directly into zuul.

question

Most helpful comment

All 12 comments

You can pretty much do anything you want with Zuul. If you have a concrete suggestion we could discuss in more detail.

My concrete use case is that I get one call from a UI service. For this one UI request I need to get data from two backend services which are behind my zuul gateway. But currently I have to make a call from the UI service to each backend service.
Is there already a way in zuul to solve this?

While I did not find a way, I implemented a bridge service which takes one request, call both required backend services an aggregates the results as a Map.

But I think this is a overhead and could be done by zuul.
What do you think?

@michl-b

I implemented a bridge service which takes one request, call both required backend services an aggregates the results as a Map.

I think this is the best solution

You could also do that right in spring mvc which zuul plugs into.

@spencergibb You mean a Spring Boot Service which provides the aggreagtion controllers and zuul in one, like this https://github.com/michl-b/spring-boot-zuul-bff/blob/master/zuul/src/main/java/de/michlb/demo/zuul/bff/controller/ProductController.java?

yup, something like that.

thanks a lot

This is not an uncommon pattern with microservices, as an example with mobile applications you often don't want to do multiple requests from the clients to different microservices and instead do 1 request to the API Gateway. I was hoping Zuul was able to handle these scenarios but that doesn't seem to be the case, using a filter for this seems strange as after the filter you would no longer want to route the request, which seem to defeat the purpose of Zuul.

@michl-b Are you able to explain how the ProductController.java example above provides zuul? As far as I can tell it's just using RestController and calling methods from ProductClient and CustomerClient.

@gihad the product controller sample doesn't use zuul, and there's no reason it should. Zuul provides an abstraction over the servlet API. Spring MVC provides another one (and IMO it happens to be better suited to this kind of use case, but that's a value judgement - you can decide for yourself).

@ahmedabbas11 thanks for that. of course you are right but i'm no longer following that bff pattern because for multiple teams you create a logic monolith between frontend & backend over multiple teams. so no one would be "responsible" for that part.
Now i think the client should take care of the backend call coordination and result aggregation.

@aivans When you are saying bridge service, are you trying to say aggregation service.? Can you please share the code.

Was this page helpful?
0 / 5 - 0 ratings