一、 在一个微服务节点的predicates下配置多个path: - Path=/test/batis/test,/test/testJmeter,具体配置如下:
spring:
application:
name: xxxx
profiles:
active: dev
cloud:
inetutils:
preferred-networks: ^192\.168\.[\d]\.[\d]+$
gateway:
enabled: true
httpclient:
connect-timeout: 1000
response-timeout: 5s
default-filters:
- StripPrefix=0
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallback
discovery:
locator:
# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务
enabled: true
# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)
routes:
- id: management-admin
uri: lb://management-admin
predicates:
- Path=/admin/**,/openbase/**
二、 在请求头中新增header参数,yml文件配置如下:文章来源:https://www.toymoban.com/news/detail-601330.html
spring:
application:
name: openapi-gate-way
profiles:
active: dev
cloud:
inetutils:
preferred-networks: ^192\.168\.[\d]\.[\d]+$
gateway:
enabled: true
httpclient:
connect-timeout: 3000
response-timeout: 5s
default-filters:
- StripPrefix=0
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallback
routes:
- id: openapi-base
uri: lb://openapi-base
predicates:
- Path=/openbase/**
filters:
# 新增请求头参数
- AddRequestHeader=name, 小明
三、自定义filter中新增请求头参数:文章来源地址https://www.toymoban.com/news/detail-601330.html
@Component
public class DemoFilter implements GatewayFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest().mutate()
.header("name", "xxx")
.header("age", 12)
.build();
return chain.filter(exchange.mutate().request(request).build());
}
@Override
public int getOrder() {
return 1;
}
}
到了这里,关于springcloud gateway 配置predicates 多个path;路由请求头新增参数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!