0

I have updated my spring boot project from 2.x to 3.x I used to use zuul filters, which become deprecated and not usable. My service is serve as a gateway proxy and also as a backend resource service with some endpoints. I have added spring-cloud-gateway-mvc in roder to replace Zuul filters and routing. I have something like this in my config:

spring:
  cloud:
    gateway:
      mvc:
        routes:
          - id: gateway
            uri: http://localhost:8250
            predicates:
              - Path=/analytics-service/api/**
            filters:
              - StripPrefix=2
          .....

In zuul I had the same thing, but also I used to have:

zuul:
  ignored-patterns:
    - /analytics-service/api/user

Which means that path - /analytics-service/api/user will be ignored buy zuul and ti will be consumed form service itself. In Spring cloud Gateway MVC I couldn't find the way of doing the same. I have tried:

https://github.com/spring-cloud/spring-cloud-gateway/issues/496#issuecomment-439986202

ANY OTHER SOLUTION?

1 Answer 1

0

Did you try creating a custom predicate? You can create a custom predicate following Spring docs

Custom predicate class:

class CustomPredicates {
    public static RequestPredicate excludePath(String excludePath) {
        return request -> !request.path().equals(excludePath);
    }
}

Use the predicate in your route configuration

@Configuration
class RouteConfiguration {

    @Bean
    public RouterFunction<ServerResponse> analyticServiceRoute() {
        return route("gateway")
            .route(excludePath("/analytics-service/api/user"), http())
            .route(path("/analytics-service/api/**"), http())
            //filters and other configuration here
            .build();
    }
}

I didn't find any way to use custom predicates from yml configuration with gateway MVC, so unfortunately you will have to convert the routes to use programmatic configuration

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.