- 基于netty的nio服务网关
- 支持http协议
- 支持https协议
- 支持cors协议
- 支持基于本地令牌桶的限流
- 相对独立的线程池
- 负载均衡采用 RandomLoadBalance 随机负载均衡算法
-
启动jar包
java -jar gateway.jar -c /root/config.json
- -v 显示版本号
- -c 指定json配置文件
- -h 显示帮助中心
-
config.json
{ "http": { "port": 8080, "redirectHttps": false }, "https": { "enable": false, "port": 8081, "keyPwd": "123456", "keyPath": "/Users/chenweidong/workspace/gateway/ssl/cwd.keystore" }, "threadPool": { "core": 150, "max": 200, "timeout": 5000 }, "mapping": { "localhost:8080": [ { "url": "123.125.115.110:80", "weight": 200 }, { "url": "220.181.57.216:80", "weight": 100 } ] }, "cors": { "enable": true, "whiteList": [] }, "flowLimits": { "enable": true, "timeout": 500, "rate": 2000000000, "maxSize": 200 } }
- http: http相关配置
- port: 端口号
- redirectHttps: 是否重定向至https
- https: https相关配置
- enable: 是否开启
- port: 端口号
- keyPwd: 证书密码
- keyPath: 证书路径
- threadPool: 单个反射配置的线程池配置
- core: 核心线程数量
- max: 最大线程数量
- timeout: 超时时间
- mapping: 映射配置,每个host对应多个反向代理地址
- url: 反向代理地址
- weight: 权重
- cors: 跨域相关配置
- enable: 是否开启跨域
- whiteList: 跨域白名单,列表为空且开启跨域情况下为允许全部origin跨域请求
- flowLimits: 限流配置
- enable: 是否开启限流
- timeout: 请求超时时间,单位ms
- rate: 令牌生产速率,单位ms
- maxSize: 令牌桶大小
- http: http相关配置