网关的核心概念:
- 路由
- 谓词
- 过滤器(11个)
spring:
cloud:
gateway:
enabled: true
discovery:
locator:
enabled: true #开启动态路由
lower-case-service-id: true
routes:
- id: trendsi-trace1
uri: lb://trendsi-trace1
predicates:
- Method=GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,TRACE
- Path=/api/tr11ace/**
filters:
- StripPrefix=2
httpclient:
connect-timeout: 100000
max-header-size: 102400
max-initial-line-length: 102400
pool:
acquire-timeout: 20000
max-connections: 5000
max-idle-time: 30s
max-life-time: 30s
name: proxy
type: fixed
response-timeout: 10s
loadbalancer:
retry:
enabled: true
sentinel:
enabled: true
transport:
dashboard: localhost:8858
port: 8719
heartbeat-interval-ms: 1000
filter:
enabled: true
metric:
charset: UTF-8
eager: true
log:
dir: ./logs/${spring.application.name}/sentinel
scg:
fallback:
mode: response
response-status: 200
response-body: "{\"code\":\"11005\",\"message\":\"请求太多了\"}"
xy:
enable: true
mvc-interceptor-enable: true
total-interceptor-enable: false
# websocket:
# proxy-ping: false
# max-frame-payload-length: 10000
# proxy:
# host:
# non-proxy-hosts-pattern:
# password:
# port:
# username:
# ssl:
# close-notify-flush-timeout:
# close-notify-read-timeout:
# default-configuration-type: tcp
# handshake-timeout:
# key-password:
# key-store:
# key-store-password:
# key-store-provider:
# key-store-type:
# trusted-x509-certificates:
# use-insecure-trust-manager: false
# wiretap: true
# refresh:
# enabled: true
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
logging:
level:
org.springframework.cloud.gateway: info
info:
app.name: ${spring.application.name}
li.name: www.li.com
build.artifactId: '@project.artifactId@'
build.version: '@project.version@'
gateway:
config:
black-url-list:
- /asd/asdasd/asdas
- /asd/asdasd/asdas1
- /asd/asdasd/asdas2
black-ip-list:
- 172.10.23.55
- 172.10.23.56
- 172.10.23.57
/module-api/**
StripPrefix=1
1标识转发时过滤/module-api
过滤器
共提供31个过滤器。
谓词
共提供11个谓词。
After
Before
Between
Cookie
Header
Method
Path(常用)
Host
Query
RemoteAddr
Weight
自定义谓词
RoutePredicateFactory
rpc 泛化调用
gateway 开源版本当前转发的是http请求,对于dubbo rpc请求,需要自行研发。
TODO