spring-cloudnetflix-eurekanetflix-zuulspring-cloud-netflixnetflix-ribbon

Filter services based on Eureka metadata with Zuul


We use Spring Cloud Netflix Zuul along with Eureka in our environment.

I understand Ribbon obtains the server list from Eureka for specified serviceId. In our case we have 4 containers of a service, one of the container is the master which performs resource intense tasks. I would like to filter out master container from list of servers so Ribbon doesnt forward any requests to the container.

How do I filter ?

Any help is appreciated.


Solution

  • I was able to filter by creating a new custom IRule

     homeautomation.ribbon.NFLoadBalancerRuleClassName=com.example.CustomZoneAvoidanceRule
    

    and extending the default ZoneAvoidanceRule

    public class CustomZoneAvoidanceRule extends ZoneAvoidanceRule {
    
    @Override
    public Server choose(final Object key) {
        final Server server = super.choose(key);
        // code to skip specific instance based on eureka metadata.
        return server;
    }
    

    }