Rapidoid - Extremely Fast, Simple and Powerful Java Web Framework!

Open source (Apache license). View benchmark... Community: [email protected]

Rapidoid as Reverse proxy and load balancer
  • Starting from v5.2, Rapidoid can be also used as a HTTP reverse proxy and load balancer.
  • A basic round-robin load balancer is included and configured as a default one.
  • The reverse proxy can be configured programatically (optionally with custom load balancers).
  • The reverse proxy can also be configured from the command-line args.
  • The command-line syntax is /path->upstream1,upstream2... e.g. /foo->https://upstream1:8080,http://upstream2:8080.
docker run -d --net=host rapidoid/rapidoid '/ -> http://localhost:8080' on.port=80
docker run -d \
    --name revproxy \
    --net=host \
    rapidoid/rapidoid \
    '/foo->https://upstream1:8080,http://upstream2:8080' \
    '/bar->http://upstream3:9090' \
    '/->https://upstream4:8080' \
    on.port=80
Main.java
import org.rapidoid.http.Req;
import org.rapidoid.reverseproxy.Reverse;
import org.rapidoid.setup.App;
import org.rapidoid.setup.On;
 
public class Main {
 
    public static void main(String[] args) {
        App.bootstrap(args);
 
        On.get("/a*").json(Req::uri);
 
        Reverse.proxy("/g")
            .roles("administrator")
            .cacheTTL(1000)
            .to("http://upstream1:8080", "http://upstream2:8080")
            .add();
    }
 
}
Main.java
import org.rapidoid.reverseproxy.Reverse;
import org.rapidoid.setup.App;
import org.rapidoid.setup.On;
 
public class Main {
 
    public static void main(String[] args) {
        App.bootstrap(args);
 
        String fooUpstream = "http://localhost:8080/foo";
 
        Reverse.proxy("/bar").to(fooUpstream).add();
        Reverse.proxy("/").to(fooUpstream).add();
 
        On.get("/foo").html("FOO");
        On.get("/foo/hi").html("FOO HI");
        On.get("/foo/hello").html("FOO HELLO");
        On.get("/bar/hi").html("BAR HI");
    }
 
}
GET /bar
FOO
GET /bar/hello
FOO HELLO
GET /bar/hi
BAR HI
GET /
FOO
GET /hello
FOO HELLO
GET /hi
FOO HI

HTTP server routes information:

Verb Path Zone Content type MVC View name Roles
ANY /* main html
ANY /bar/* main html
GET /bar/hi main html
GET /foo main html
GET /foo/hello main html
GET /foo/hi main html
Main.java
import org.rapidoid.http.Req;
import org.rapidoid.reverseproxy.LoadBalancer;
import org.rapidoid.reverseproxy.ProxyUpstream;
import org.rapidoid.reverseproxy.Reverse;
import org.rapidoid.setup.App;
 
import java.util.List;
 
public class Main {
 
    public static void main(String[] args) {
        App.bootstrap(args);
 
        LoadBalancer lb = (Req req, List<ProxyUpstream> candidates) -> {
            int index = 0; // FIXME implement load balancing strategy
            return candidates.get(index);
        };
 
        Reverse.proxy("/")
            .to("http://upstream1:8080", "http://upstream2:8080")
            .loadBalancer(lb)
            .add();
    }
 
}