Netflix / zuul

Zuul is a gateway service that provides dynamic routing, monitoring, resiliency, security, and more.
Apache License 2.0
13.45k stars 2.37k forks source link

[Question] Is there any way to use setroutehost() with ProxyEndpoint in Zuul 2.x? #442

Closed jeminkim closed 6 years ago

jeminkim commented 6 years ago

I create my system with Zuul 1.X and I want to move to Zuul 2.X. Currently, my system have database for routing table and use setroutehost() in my customfilter without eureka.

I tried to use that setroutehost() with ProxyEndpoint filter, but it's not routing to origin. I saw ProxyEndpoint filter code, but there's no code for processing setroutehost.

And I also try {origin}.ribbon.listOfServer in properties, and it's working, but I want to use dynamic routing settings in inbound filter.

Q1. Is there any way to use setroutehost() with ProxyEndpoint filter?

I saw ProxyEndpoint filter code, there's some functions (like injectCustomVip()) which can be override. Maybe that function can be use for dynamic routing.

Q2. Can I create new endpoint filter use ProxyEndpoint filter? (class fooEndpoint extends ProxyEndpoint things..)

If you have some reference manual or code, please answer to me :)

artgon commented 6 years ago

This is a good question, I need to add some documentation to cover this case.

  1. We're using the Ribbon client configuration for routing. You can define your Ribbon clients in the properties file with their servers using <client>.ribbon.listOfServers. Then can set your VIP/clientName in the filters: https://github.com/Netflix/zuul/blob/2.1/zuul-sample/src/main/groovy/com/netflix/zuul/sample/filters/inbound/Routes.groovy#L55.

  2. Yes, you can override the ProxyEndpoint class with your own implementation. The method to override is here: https://github.com/Netflix/zuul/blob/ec364dfe331f2b724f7e16d5606f6d293ece7cdd/zuul-core/src/main/java/com/netflix/zuul/netty/filter/ZuulEndPointRunner.java#L187

This is something we should make easier but unfortunately you'll have to also create subclasses for ZuulEndpointRunner and BaseZuulChannelInitializer.