网关属性配置
本篇主要讲解如何在 Apache Shenyu 网关配置 ShenYu 的相关属性。
属性配置
shenyu:
selectorMatchCache:
## selector L1 cache
cache:
enabled: false
initialCapacity: 10000 # initial capacity in cache
maximumSize: 10000 # max size in cache
## selector L2 cache, use trie as L2 cache
trie:
enabled: false
cacheSize: 128 # the number of plug-ins
matchMode: antPathMatch
ruleMatchCache:
## rule L1 cache
cache:
enabled: true
initialCapacity: 10000 # initial capacity in cache
maximumSize: 65536 # max size in cache
## rule L2 cache, use trie as L2 cache
trie:
enabled: false
cacheSize: 1024 # the number of selectors
matchMode: antPathMatch
netty:
http:
webServerFactoryEnabled: true
selectCount: 1
workerCount: 4
accessLog: false
serverSocketChannel:
soRcvBuf: 87380
soBackLog: 128
soReuseAddr: true
connectTimeoutMillis: 30000
writeBufferHighWaterMark: 65536
writeBufferLowWaterMark: 32768
writeSpinCount: 16
autoRead: false
allocType: "pooled"
messageSizeEstimator: 8
singleEventExecutorPerGroup: true
socketChannel:
soKeepAlive: false
soReuseAddr: false
soLinger: -1
tcpNoDelay: true
soRcvBuf: 87380
soSndBuf: 16384
ipTos: 0
allowHalfClosure: false
connectTimeoutMillis: 30000
writeBufferHighWaterMark: 65536
writeBufferLowWaterMark: 32768
writeSpinCount: 16
autoRead: false
allocType: "pooled"
messageSizeEstimator: 8
singleEventExecutorPerGroup: true
instance:
enabled: false
registerType: zookeeper #etcd #consul
serverLists: localhost:2181 #http://localhost:2379 #localhost:8848
props:
# httpclient:
# strategy: webClient
# connectTimeout: 45000
# responseTimeout: 3000
# readerIdleTime: 3000
# writerIdleTime: 3000
# allIdleTime: 3000
# readTimeout: 3000
# writeTimeout: 3000
# wiretap: false
# keepAlive: false
# pool:
# type: ELASTIC
# name: proxy
# maxConnections: 16
# acquireTimeout: 45000
# maxIdleTime: 3000
# proxy:
# host:
# port:
# username:
# password:
# nonProxyHostsPattern:
# ssl:
# useInsecureTrustManager: false
# keyStoreType: PKCS12
# keyStorePath: classpath:keystore.p12
# keyStorePassword: 123456
# keyStoreProvider:
# keyPassword: 123456
# trustedX509Certificates:
# handshakeTimeout:
# closeNotifyFlushTimeout:
# closeNotifyReadTimeout:
# defaultConfigurationType:
sync:
websocket:
urls: ws://localhost:9095/websocket
allowOrigin: ws://localhost:9195
# zookeeper:
# url: localhost:2181
# sessionTimeout: 5000
# connectionTimeout: 2000
# http:
# url: http://localhost:9095
# nacos:
# url: localhost:8848
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
# username:
# password:
# acm:
# enabled: false
# endpoint: acm.aliyun.com
# namespace:
# accessKey:
# secretKey:
# etcd:
# url: http://localhost:2379
# consul:
# url: http://localhost:8500
# waitTime: 1000
# watchDelay: 1000
cross:
enabled: true
allowedHeaders:
allowedMethods: "*"
allowedAnyOrigin: false
allowedOrigin:
# format : schema://prefix spacer domain
# Access-Control-Allow-Origin: "http://a.apache.org,http://b.apache.org"
spacer: "."
domain: apache.org
prefixes:
- a # a.apache.org
- b # b.apache.org
origins:
- c.apache.org
- d.apache.org
- http://e.apache.org
originRegex: ^http(|s)://(.*\.|)abc.com$
allowedExpose: ""
maxAge: "18000"
allowCredentials: true
switchConfig:
local: true
file:
enabled: true
maxSize : 10
exclude:
enabled: false
paths:
- /favicon.ico
fallback:
enabled: false
paths:
- /fallback/hystrix
- /fallback/resilience4j
health:
enabled: false
paths:
- /actuator/health
- /health_check
alert:
enabled: true
admins: localhost:9095
extPlugin:
path:
enabled: true
threads: 1
scheduleTime: 300
scheduleDelay: 30
scheduler:
enabled: false
type: fixed
threads: 16
upstreamCheck:
enabled: false
timeout: 3000
healthyThreshold: 1
unhealthyThreshold: 1
interval: 5000
printEnabled: true
printInterval: 60000
ribbon:
serverListRefreshInterval: 10000
metrics:
enabled: false
name : prometheus
host: 127.0.0.1
port: 8090
jmxConfig:
props:
jvm_enabled: true
sharedPool:
enable: true
prefix: "shenyu-shared"
corePoolSize: 200
maximumPoolSize: 2000
keepAliveTime: 60000
maxWorkQueueMemory: 1073741824 # 1GB
maxFreeMemory: 268435456 # 256MB
属性详解
shenyu.matchCache 配置
- 选择器匹配缓存配置
| 字段 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| enabled | Boolean | false | No | 是否开启选择器缓存 |
| initialCapacity | Integer | 10000 | No | 选择器缓存初始化容量 |
| maximumSize | Integer | 10000 | No | 选择器缓存最大数量 |
- 选择器前缀树缓存配置
| 字段 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| enabled | Boolean | false | No | 是否开启选择器前缀树缓存 |
| cacheSize | Integer | 512 | No | 前缀树缓存大小 |
| matchMode | String | antPathMatch | Yes | shenyu路径匹配模式,shenyu支持两种匹配模式: antPathMatch and pathPattern |
- 规则匹配缓存配置
| 字段 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| enabled | Boolean | false | No | 是否开启选择器缓存 |
| initialCapacity | Integer | 10000 | No | 规则缓存初始化容量 |
| maximumSize | Integer | 10000 | No | 规则缓存最大数量 |
- 规则前缀树缓存配置
| 字段 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| enabled | Boolean | false | No | 是否开启规则前缀树缓存 |
| cacheSize | Integer | 512 | No | 前缀树缓存大小 |
| matchMode | String | antPathMatch | Yes | shenyu路径匹配模式,shenyu支持两种匹配模式: antPathMatch and pathPattern |
shenyu默认开启L1和L2缓存, shenyu前缀树支持两种匹配模式,我们非常建议您使用pathPattern作为默认的匹配模式。
pathPattern: org.springframework.web.util.pattern.PathPatternParser antPathMatch: org.springframework.util.AntPathMatcher
当您将matchRestful标记为true时,我们建议将所有缓存标记为false,以避免匹配冲突。