SPRING CLOUD GATEWAY MVC – EUREKA DISCOVERY CLIENT

I am facing the case of a “Legacy” gateway which has to create routes based on services registered with a DiscoveryClient compatible service registry (Eureka) with the constraints based on Springboot 3.2 VS spring-cloud-gateway-server is not an option.

After reading the MVC version of the Spring Cloud Gateway Reference Documentation, studying the spring-cloud-gateway-server-examples

I want to try spring-cloud-gateway-server-mvc, but I haven’t found a startup example of a gateway based on spring-cloud-gateway-server-mvc <==> ( ? RouteLocator ? ) <==> (Eureka)DiscoveryClient yet.

For example How to obtain the list of routes for a custom filter? :

//https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/writing-custom-predicates-and-filters.html
public class CustomRouteFilterConfiguration {

    RouteLocator routeLocator;

    @Bean
    public RouterFunction<ServerResponse> TokenRelay(){
        return route("access_control_route")
            .route(path("/**"), http())
            .filter(filterOnRoutes(routeLocator))
            //
            .build();
    }

}
public class RoutesFilterFunctions {

    @Shortcut
    public static HandlerFilterFunction<ServerResponse, ServerResponse> filterOnRoutes(JHipsterProperties jHipsterProperties, RouteLocator routeLocator) {
        return (request, next) -> {
            boolean isAuthorizedRequest = false;         
            for (Route route : routeLocator.getRoutes()) {
             //do smthg here
            }
            return next.handle(request);
        };
    }
}

I tried spring-cloud-gateway-server-mvc gateway which has to create routes based on services registered with a DiscoveryClient compatible service registry (Eureka) but don’t understand how to obtain the list of routes.

Leave a Comment