繁体   English   中英

Spring Cloud Gateway和Consul Server

[英]Spring cloud Gateway and Consul Server

请帮忙。 我有Spring Cloud Gateway和Consul Server。 在Spring Cloud Gateway中,我使用“ cloud:gateway:discovery:locator:enabled:true”。 我可以发送对在Consul( ServiceName )中注册的服务的请求。 例如URL“ / ServiceName / foo / bar”。 我可以自定义Spring Cloud Gateway以便查询看起来像/ foo / bar / ServiceName / baz吗?

是的你可以

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}'"

我的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