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 :
1) All the request will enter the system via gateway service -- working
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.
I want to achieve the above use case dynamically using zuul routing filter and eureka. I looked into PreDecoration filter and tried to the following. My gateway service is running on port 8080
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;
}
}