- 基于netty和okHttp的反向代理网关
- 支持http协议
- 支持https协议
- 支持cors协议
- 支持基于本地令牌桶的限流
- 相对独立的线程池
- 负载均衡采用 RandomLoadBalance 随机负载均衡算法
- 支持熔断不可用服务,并在单独线程中进行重试,成功以后重新设置为可用
- 在linux下采用epoll其他系统采用nio
- 静态文件映射
-
启动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/xxx/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 } ] }, "static": { "localhost:8080": "/Users/xxx/workspace/gateway" }, "cors": { "enable": true, "whiteList": [] }, "flowLimits": { "enable": true, "timeout": 500, "rate": 5, "maxSize": 200 } }- http: http相关配置
- port: 端口号
- redirectHttps: 是否重定向至https
- https: https相关配置
- enable: 是否开启
- port: 端口号
- keyPwd: 证书密码
- keyPath: 证书路径
- threadPool: 单个反射配置的线程池配置
- core: 核心线程数量
- max: 最大线程数量
- timeout: 超时时间
- mapping: 映射配置,每个host对应多个反向代理地址
- url: 反向代理地址
- weight: 权重
- static: 静态文件映射
- key host地址
- value 本地映射文件夹
- cors: 跨域相关配置
- enable: 是否开启跨域
- whiteList: 跨域白名单,列表为空且开启跨域情况下为允许全部origin跨域请求
- flowLimits: 限流配置
- enable: 是否开启限流
- rate: 令牌生产速率,单位ms
- maxSize: 令牌桶大小
- http: http相关配置