简体   繁体   中英

Spring cloud Gateway and Consul Server

Please help. I have Spring Cloud Gateway and Consul Server. In Spring Cloud Gateway i'm use "cloud:gateway:discovery:locator:enabled:true". I can send requests for services registered in the Consul ( ServiceName ). For example URL "/ ServiceName /foo/bar". Can I customize Spring Cloud Gateway so that the queries would look like /foo/ bar/ ServiceName /baz ?

Yes you can

spring.cloud.gateway.discovery.locator.predicates[0].name: Path
spring.cloud.gateway.discovery.locator.predicates[0].args[pattern]: "'/foo/bar/'+serviceId+'/**'"
spring.cloud.gateway.discovery.locator.filters[0].name: RewritePath
spring.cloud.gateway.discovery.locator.filters[0].args[regexp]: "'/' + serviceId + '/foo/bar/(?<remaining>.*)'"
spring.cloud.gateway.discovery.locator.filters[0].args[replacement]: "'/${remaining}'"

My version for application.yml

spring:
  cloud:
    gateway:
      locator:
        enabled: true
        predicates:
          - name: Path
            args:
              pattern: "'/foo/bar/' + serviceId + '/**'"
        filters:
          - name: RewritePath
            args:
              regexp: "'/foo/bar/' + serviceId + '/(?<remaining>.*)'"
              replacement: "'/foo/bar/' + serviceId + '/${remaining}'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM