各类断言工厂(路由判断)
path路由断言工厂
- 配置
- id: pathInfo
uri: http://www.example.com/
predicates:
- Path=/abcd/{segment}
- 访问地址:http://127.0.0.1:10011/abcd/12312
query路由断言工厂
- 配置
- id: queryInfo
uri: http://www.example.com/
predicates:
- Query= foo,bb
- 访问地址 http://127.0.0.1:10011/abcdeeee?foo=bb
method路由断言工厂`
- 配置
- id: methodnfo
uri: http://www.example.com/
predicates:
- Method= DELETE
- 访问地址:
curl --location --request DELETE 'http://127.0.0.1:10011/adfasfsdfdsd'
head 路由断言工厂
- 配置
- id: headinfo
uri: http://www.example.com/
predicates:
- Header=x-ragnar-traceid,[wd]
- 访问地址
curl --location --request GET 'http://127.0.0.1:10011/adfasfsdfdsd12312'
--header 'x-ragnar-traceid: 123213123'
自定义路由断言工厂
自定义断言工厂代码
代码语言:javascript复制@Slf4j
@Component
public class GrayRoutePredicateFactory extends AbstractRoutePredicateFactory<GrayCfg> {
public GrayRoutePredicateFactory() {
super(GrayCfg.class);
}
@Override
public Predicate<ServerWebExchange> apply(GrayCfg cfg) {
return serverWebExchange -> {
log.info("enter GrayRoutePredicateFactory" cfg.isGrayStatus());
if (cfg.isGrayStatus()) {
log.info(" GrayRoutePredicateFactory hit start gray");
return true;
}
return false;
};
}
}
自定义断言工厂配置
代码语言:txt复制 - id: grayinfo
uri: http://www.baidu.com/
predicates:
- Path=/eee/**
- name: Gray
args:
grayStatus: true