Skip to content

feigezc/gateway

 
 

Gateway

Version License

Overview

  • 基于netty和okHttp的反向代理网关
  1. 支持http协议
  2. 支持https协议
  3. 支持cors协议
  4. 支持基于本地令牌桶的限流
  5. 相对独立的线程池
  6. 负载均衡采用 RandomLoadBalance 随机负载均衡算法
  7. 支持熔断不可用服务,并在单独线程中进行重试,成功以后重新设置为可用
  8. 在linux下采用epoll其他系统采用nio
  9. 静态文件映射

Usage

  • 启动jar包

    java -jar gateway.jar -c /root/config.json
    1. -v 显示版本号
    2. -c 指定json配置文件
    3. -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
      }
    }
    1. http: http相关配置
      1. port: 端口号
      2. redirectHttps: 是否重定向至https
    2. https: https相关配置
      1. enable: 是否开启
      2. port: 端口号
      3. keyPwd: 证书密码
      4. keyPath: 证书路径
    3. threadPool: 单个反射配置的线程池配置
      1. core: 核心线程数量
      2. max: 最大线程数量
      3. timeout: 超时时间
    4. mapping: 映射配置,每个host对应多个反向代理地址
      1. url: 反向代理地址
      2. weight: 权重
    5. static: 静态文件映射
      1. key host地址
      2. value 本地映射文件夹
    6. cors: 跨域相关配置
      1. enable: 是否开启跨域
      2. whiteList: 跨域白名单,列表为空且开启跨域情况下为允许全部origin跨域请求
    7. flowLimits: 限流配置
      1. enable: 是否开启限流
      2. rate: 令牌生产速率,单位ms
      3. maxSize: 令牌桶大小

About

基于netty的反向代理api网关

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%