title: Zuul dynamic routing using pre filter and eureka
body: <p>I am creating a sample consist of 3 (Service A, Service B and Service C)  microservices. All the 3 services along with the gateway service ( zuul ) get registered with eureka. My use case is :</p>
  
  <p>1) All the request will enter the system via gateway service -- working</p>
  
  <p>2) For every request targeted for Service C, gateway service should first call Service A to perform certain action. On positive response from Service A, the request should get forwarded to Service B. Once we get positive response from both Service A and Service B, the request should finally be forwarded to Service C. </p>
  
  <p>I want to achieve the above use case dynamically using zuul routing filter and eureka. I looked into <a href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java" rel="nofollow">PreDecoration</a> filter and tried to the following. My gateway service is running on port 8080</p>
  
  <pre><code>zuul:
    routes:
      all:
        path: /** 
        url: http://localhost:8761
  
  
  public class CustomFilter extends ZuulFilter{
  
      @Override
      public boolean shouldFilter() {
          return true;
      }
  
      @Override
      public Object run() {
          RequestContext ctx = RequestContext.getCurrentContext();
          ctx.set("serviceId", “service-a”);
          ctx.setRouteHost(new URL("http://localhost:8080”));
  
          return null;
      }
  
      @Override
      public String filterType() {
          return "pre";
      }
  
      @Override
      public int filterOrder() {
          return 1;
      }
  
  }
  </code></pre>