简体   繁体   English

Spring Cloud Gateway和Consul Server

[英]Spring cloud Gateway and Consul Server

Please help. 请帮忙。 I have Spring Cloud Gateway and Consul Server. 我有Spring Cloud Gateway和Consul Server。 In Spring Cloud Gateway i'm use "cloud:gateway:discovery:locator:enabled:true". 在Spring Cloud Gateway中,我使用“ cloud:gateway:discovery:locator:enabled:true”。 I can send requests for services registered in the Consul ( ServiceName ). 我可以发送对在Consul( ServiceName )中注册的服务的请求。 For example URL "/ ServiceName /foo/bar". 例如URL“ / ServiceName / foo / bar”。 Can I customize Spring Cloud Gateway so that the queries would look like /foo/ bar/ ServiceName /baz ? 我可以自定义Spring Cloud Gateway以便查询看起来像/ 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 我的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}'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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