【问题标题】:Spring cloud Gateway and Consul ServerSpring Cloud Gateway 和 Consul Server
【发布时间】:2019-06-24 21:41:39
【问题描述】:

请帮忙。 我有 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 spring-cloud gateway spring-cloud-gateway


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-01
        • 2020-05-18
        • 2023-03-09
        • 2021-10-20
        • 2016-02-18
        • 2015-11-04
        • 2020-11-04
        • 2020-07-04
        相关资源
        最近更新 更多