I am creating a sample consisting of microservices 3 (services A, services B and services C). All 3 services together with the gateway (zuul) are registered in eureka. My use case:
1) The entire request will enter the system through the gateway - working
2) For each request destined for service C, the gateway service must first call service A to perform certain actions. With a positive response from service A, the request should be sent to service B. As soon as we receive a positive response from both service A and service B, the request should finally be sent to service C.
I want to achieve the above use case dynamically using zuul routing filter and eureka. I looked at PreDecoration and tried the following. My gateway service runs 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;
}
}
source
share