spring:
cloud:
gateway:
routes:
- id: after_route
uri: http://127.0.0.1:8082
predicates:
- After=2021-08-16T07:36:00.000+08:00[Asia/Shanghai]
[
{
"id": "after_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "After",
"args": {
"datetime": "2021-08-16T07:36:00.000+08:00[Asia/Shanghai]"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: before_route
uri: http://127.0.0.1:8082
predicates:
- Before=2021-08-16T07:36:00.000+08:00[Asia/Shanghai]
[
{
"id": "before_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Before",
"args": {
"datetime": "2021-08-16T07:36:00.000+08:00[Asia/Shanghai]"
}
}
]
}
]
spring:
application:
name: hello-gateway
cloud:
gateway:
routes:
- id: between_route
uri: http://127.0.0.1:8082
predicates:
- Between=2021-08-16T07:36:00.000+08:00[Asia/Shanghai], 2021-08-16T08:15:00.000+08:00[Asia/Shanghai]
[
{
"id": "path_route_addr",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Between",
"args": {
"datetime1": "2021-08-16T07:36:00.000+08:00[Asia/Shanghai]",
"datetime2": "2021-08-16T08:18:00.000+08:00[Asia/Shanghai]"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=chocolate, ch.p
[
{
"id": "cookie_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Cookie",
"args": {
"name": "chocolate",
"regexp": "ch.p"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id, \d+
[
{
"id": "header_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Header",
"args": {
"header": "X-Request-Id",
"regexp": "\\d+"
}
}
]
}
]
用postman测试的参数填写和结果如下:
spring:
cloud:
gateway:
routes:
- id: host_route
uri: http://127.0.0.1:8082
predicates:
- Host=test.com:8081,**.anotherhost.org
[
{
"id": "header_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Host",
"args": {
"regex": "test.com:8086"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: method_route
uri: http://127.0.0.1:8082
predicates:
- Method=GET,POST
[
{
"id": "method_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Method",
"args": {
"methods": "GET"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: path_route
uri: http://127.0.0.1:8082
predicates:
- Path=/hello/{segment},/lbtest/{segment}
[
{
"id": "path_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Path",
"args": {
"pattern": "/hello/{segment}"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: query_route
uri: http://127.0.0.1:8082
predicates:
- Query=name
spring:
cloud:
gateway:
routes:
- id: query_route
uri: http://127.0.0.1:8082
predicates:
- Query=name,aaa.
[
{
"id": "query_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "Query",
"args": {
"param": "name",
"regexp": "aaa."
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: remoteaddr_route
uri: http://127.0.0.1:8082
predicates:
- RemoteAddr=192.168.50.134/24
[
{
"id": "remoteaddr_route",
"uri": "http://127.0.0.1:8082",
"predicates":[
{
"name": "RemoteAddr",
"args": {
"sources": "192.168.50.134/24"
}
}
]
}
]
spring:
cloud:
gateway:
routes:
- id: weight_high
uri: http://192.168.50.134:8082
predicates:
- Weight=group1, 8
- id: weight_low
uri: http://192.168.50.135:8082
predicates:
- Weight=group1, 2