Spring Cloud Gateway和Consul Server

时间:2019-01-31 12:16:34

标签: spring cloud spring-cloud gateway spring-cloud-gateway

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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