- API proxy gateway base on netty and okHttp.
- Support http protocol.
- Support https protocol.
- Support cors protocol.
- Support local flow limits base on token bucket.
- Every proxy has independent thread pool.
- Load balance
- RandomLoadBalance
- ConsistentHash
- RoundRobinLoadBalance
- LeastActiveLoadBalance
- Support fuse service which is offline,then retest service in single thread,when it is reachable,take it online.
- Use epoll model in Linux,other uses nio model.
- Static file mapping.
- Support consul auto service discovery.if it is enable,origin mapping config will be failure,every node has same weight.
- Support zookeeper auto service discovery.If it is enable,origin mapping config will be failure,every node has same weight,zk priority is higher than consul.
- Print detail log in developer mode,and print log which level is higher than 'warn' in production environment.
Download the latest release
-
start jar package
java -jar gateway.jar -c /root/config.json
- -v version
- -c json config file path
- -h show help info
-
config.json
{ "mode": "dev", "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": { "mode": "com.github.cwdtom.gateway.environment.lb.ConsistentHash", "list": { "127.0.0.1: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, "allowMethods": "GET, POST, HEAD, PUT, PATCH, DELETE", "whiteList": [] }, "flowLimits": { "enable": true, "timeout": 500, "rate": 5, "maxSize": 200 }, "filter": { "before": [ "com.github.cwdtom.gateway.filter.BeforeTestFilter" ], "after": [ "com.github.cwdtom.gateway.filter.AfterTestFilter" ] }, "consul": { "enable": true, "host": "192.168.0.236:8500", "mapping": { "test": [ "localhost:8080" ] } }, "zk": { "enable": true, "host": "127.0.0.1:2181", "mapping": { "test": [ "localhost:8080" ] } } }
- mode: If it is not 'dev',nothing but log level higher than 'warn' print and shutdown resource leak detector.
- http: http config.
- port: http service port.
- redirectHttps: Whether need redirect https or not.
- https: https config.
- enable: enable https service.
- port: https service port.
- keyPwd: SSL certificate password.
- keyPath: SSL certificate file path.
- threadPool: single proxy thread pool config.
- core: core thread count.
- max: max thread count.
- timeout: thread pool timeout.
- mapping: mapping config,every host mapping multiple proxy address.
- mode: load balance algorithm,default RandomLoadBalance.
- list: mapping list.
- key: host.
- value: proxy address list.
- url: proxy address.
- weight: weight.
- static: static file mapping.
- key: host.
- value: local folder.
- cors: cors config.
- enable: enable cors.
- allowMethods: allowed request methods.
- whiteList: cors white list,when white list is empty and cors enable,allow all requested.
- flowLimits: flow limits config.
- enable: enable flow limits.
- rate: token production rate,unit millisecond.
- maxSize: token bucket size.
- filter: request filter,the execution order is same as this config.
- before: pre filter.
- after: post filter.
- consul: consul config.
- enable: enable consul,if enable origin mapping will be failure.
- host: consul address.
- mapping: service mapping.
- key: service name(spring.application.name).
- value: host list
- zk: zookeeper config
- enable: enable zookeeper,if enable origin mapping will be failure.
- host: zookeeper address
- mapping: service mapping.
- key: service name(spring.application.name).
- value: host list
-
Load balance algorithm:Support customize algorithm.Algorithm class need extends UrlMapping class.Father class has proxy mapping map variable.
public class RandomLoadBalance extends UrlMapping { @Override public Mapper getLoadBalance(String host, String ip) { // do something } }
-
filter:Support customize filter.Filter class need implements BeforeFilter interface or AfterFilter interface.
- pre filter,return whether continue or not.
public class TestFilter implements BeforeFilter { @Override public boolean filter(FullHttpRequest request, byte[] content) { // do something return false; } }
- post filter.
public class TestFilter implements AfterFilter { @Override public void filter(FullHttpResponse response) { // do something } }