网关属性配置
本篇主要讲解如何在 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: true
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
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,以避免匹配冲突。
shenyu.NettyTcpProperties 配置
Apache ShenYu reactor-netty 配置
| 名称 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| webServerFactoryEnabled | Boolean | true | 否 | 是否开启自定义参数,true-开启,false-可以自行配置NettyReactiveWebServerFactory |
| selectCount | Integer | 1 | 否 | Netty 选择器数 |
| workerCount | Integer | 4 | 否 | Netty 工作线程数 |
| accessLog | Boolean | false | 否 | netty request parameters. |
| ServerSocketChannelConfig | ||||
| soRcvBuf | Integer | -- | 否 | Socket参数,TCP数据接收缓冲区大小,默认由系统决定 |
| soBackLog | Integer | 128 | 否 | Socket参数,服务端接受连接的队列长度 |
| soReuseAddr | Boolean | true | 否 | Socket 参数,是否复用地址,reactor-netty中默认值为true |
| connectTimeoutMillis | Integer | 30000 | 否 | Netty 参数,连接超时时间 |
| writeBufferHighWaterMark | Integer | 65536 | 否 | Netty 参数,通道水位线上限 |
| writeBufferLowWaterMark | Integer | 32768 | 否 | Netty 参数,通道水位线下限 |
| writeSpinCount | Integer | 16 | 否 | Netty参数,一个Loop写操作执行的最大次数 |
| autoRead | Boolean | false | 否 | Netty参数,自动读取,reactor-netty中默认值为false,且只能为false |
| allocType | String | pooled | 否 | Netty参数,ByteBuf的分配器 |
| messageSizeEstimator | Integer | 8 | 否 | Netty参数, 消息大小估算器, 用于估算ByteBuf,ByteBufHolder和FileRegion大小 |
| singleEventExecutorPerGroup | Boolean | true | 否 | Netty参数, 单线程执行ChannelPipeline中的事件 |
| SocketChannelConfig | ||||
| soKeepAlive | Boolean | false | 否 | Socket 参数,是否启用心跳保活机制 |
| soReuseAddr | Boolean | true | 否 | Socket 参数,是否复用地址,reactor-netty中默认值为true |
| soLinger | Integer | -1 | 否 | Socket 参数,关闭 Socket 的延迟时间 |
| tcpNoDelay | Boolean | true | 否 | Socket 参数,是否启用 Nagle 算法 |
| soRcvBuf | Integer | -- | 否 | Socket参数,TCP数据接收缓冲区大小,默认由系统决定 |
| soSndBuf | Integer | -- | 否 | Socket参数,TCP数据发送缓冲区大小,默认由系统决定 |
| ipTos | Integer | 0 | 否 | IP参数,设置IP头部的Type-of-Service字段,用于描述IP包的优先级和QoS选项 |
| allowHalfClosure | Boolean | false | 否 | Netty参数,一个连接的远端关闭时本地端是否关闭 |
| connectTimeoutMillis | Integer | 30000 | 否 | Netty 参数,连接超时时间 |
| writeBufferHighWaterMark | Integer | 65536 | 否 | Netty 参数,通道水位线上限 |
| writeBufferLowWaterMark | Integer | 32768 | 否 | Netty 参数,通道水位线下限 |
| writeSpinCount | Integer | 16 | 否 | Netty参数,一个Loop写操作执行的最大次数 |
| autoRead | Boolean | false | 否 | Netty参数,自动读取,reactor-netty中默认值为false,且只能为false |
| allocType | String | pooled | 否 | Netty参数,ByteBuf的分配器 |
| messageSizeEstimator | Integer | 8 | 否 | Netty参数, 消息大小估算器, 用于估算ByteBuf,ByteBufHolder和FileRegion大小 |
| singleEventExecutorPerGroup | Boolean | true | 否 | Netty参数, 单线程执行ChannelPipeline中的事件 |
shenyu.register 配置
Apache ShenYu 网关注册到注册中心的相关配置,注册中心配置请参考 注册中心配置
| 名称 |
|---|