2

I am currently implementing Spring Cloud would like to specify my routes into multiple files as an example below :

Initially we had one configuration having routes to A & B rest endpoints.

Spring Cloud Gateway fronts Rest Endpoint A and Rest Endpoint B 
    - Created YML 1 with routes to A and B (Refer below)

YML 1
----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400

A few days later I need to add routes to another Rest Endpoint C. I would not like to touch the original configuration (YML 1) instead would want to create a new YML for C and expect route C to append to original routing of A and B (similar to Apache Httpd WebProxy).

To have multiple YML I refer to suggestions from the below link : Spring Boot and multiple external configuration files

Spring Cloud Gateway fronts Rest Endpoint A, B and C
    - Existing YML 1 with routes to A and B (Refer below)
    - Created YML 2 with route to C (Refer below)
YML 1
----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400

YML 2
-----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500
Expectation 
-----------------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500
Actual Outcome 
-------------------------           
spring:
  cloud:
    gateway:
      routes:
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500

Routes(A, B, C) do not get appended, instead it only picks up the latest configuration (YML 2 - Route C) in the property chain                      

If someone else has any bright ideas on how to implement this please suggest. All help and comments are more than welcome.

1 Answers1

-1

The best that I've come up with (which is really not much of a solution but a compromise) is to use large ASCII headers (with some online tool like patorjk's). It makes it easier to navigate at a glance, especially when using Sublime Text.

Sublime Text with "Headers"

It's far, far from ideal, but I find it'll do for now.

Justin L
  • 39
  • 3
  • 7
  • I don't think this is possible based on this issue log - https://github.com/spring-cloud/spring-cloud-gateway/issues/831. If you are using any CI-CD pipeline, may be you can try to combine the multiple YAML files as a step in the pipeline before deployment – Jacob Feb 09 '21 at 08:40