[英]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.