I have used spring boot version 3.1,4 and java 17 and spring cloud gateway. I wrote a router to call other 2 APIS in microservices and return one of the API's response.

Here, rewrite filter executing and returning repones and next filter call void method. Now all 2 services APIs are called and able to get response. The problem is after getting response and data added to both service the request will not terminate still in running. is there any way to stop request after executing services calls.

need to execute filters and get response and the request should be stop.

Bean
public RouteLocator Router(RouteLocatorBuilder builder, ServiceA serviceA) {
     return builder.routes().route("id",
              p -> p.path("/xxxx/yyyyy/zzzzzzzz")
                   .and().readBody(RequestDto.class, requestBody -> true)
                   .filters(f -> f.rewritePath("xxxx/yyyyy/zzzz-zzzz", "v1/admin/path")
                   .filter((exchange, chain) -> {
                    RequestDto requestBody = exchange.getAttribute("cachedRequestBodyObject");
                    if (requestBody.getStatus().equalsIgnoreCase("ENABLES")) {
                        ServiceA.add(requestBody,exchange.getRequest().getHeaders());
}

                             return chain.filter(exchange);
                           }))
              .uri(ServiceUrl));

}
0

There are 0 best solutions below