A Round-Robin Load Balancer using JBoss EAP 8.1

Besides hosting applications that serve business logic, JBoss EAP 8.1 can also provide load-balancing capabilities. This is especially useful when JBoss EAP is placed as a reverse proxy in front of other systems.

Conceptually, it would look something like the image below. To keep things simple, every application involved will be located on the same server:

Let’s start by editing JBoss EAP’s standalone.xml and adding two new hosts behind it

<?xml version="1.0" encoding="UTF-8"?>

<server xmlns="urn:jboss:domain:20.0">
    
    <profile>
        <subsystem xmlns="urn:jboss:domain:undertow:14.0"
                   default-virtual-host="default-host"
                   default-servlet-container="default"
                   default-server="default-server"
                   statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}"
                   default-security-domain="other">
            
            <byte-buffer-pool name="default"/>
            <buffer-cache name="default"/>
            
            <server name="default-server">
                <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
                <https-listener name="https" socket-binding="https" ssl-context="applicationSSC" enable-http2="true"/>
                
                <host name="default-host" alias="localhost">
                    <location name="/" handler="proxy"/>
                    <http-invoker http-authentication-factory="application-http-authentication"/>
                </host>
            </server>
            
            <servlet-container name="default">
                <jsp-config/>
                <websockets/>
            </servlet-container>
            
            <handlers>
                <reverse-proxy name="proxy" connection-idle-timeout="60">
                    <host name="backend-host1" outbound-socket-binding="backend-host1" scheme="http" instance-id="backend-host1" path="/"/>
                    <host name="backend-host2" outbound-socket-binding="backend-host2" scheme="http" instance-id="backend-host2" path="/"/>
                </reverse-proxy>
            </handlers>
            
            <application-security-domains>
                <application-security-domain name="other" security-domain="ApplicationDomain"/>
            </application-security-domains>
        </subsystem>
    </profile>
    
    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <outbound-socket-binding name="backend-host1">
            <remote-destination host="127.0.0.1" port="8081"/>
        </outbound-socket-binding>
        
        <outbound-socket-binding name="backend-host2">
            <remote-destination host="127.0.0.1" port="8082"/>
        </outbound-socket-binding>
    </socket-binding-group>
</server>

By default, the load balancing in JBoss EAP uses the round-robin strategy. This means the response alternates between each backend host with every request. For example,

$ curl -kv http://localhost:8080/
*   Trying [::1]:8080...
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Type: application/json
< content-length: 23
< Date: Mon, 18 Aug 2025 07:45:21 GMT
<
* Connection #0 to host localhost left intact
{"hello":"from host 1"}                                       

$ curl -kv http://localhost:8080/
*   Trying [::1]:8080...
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< transfer-encoding: chunked
< Content-Type: application/json
< Date: Mon, 18 Aug 2025 07:45:19 GMT
<
* Connection #0 to host localhost left intact
{"hello":"from host 2"}                                                                            ?

As shown above, the responses alternate between host 1 and host 2.

Conclusion
With just a few configuration changes, JBoss EAP 8.1 can be used as both a reverse proxy and a load balancer for HTTP requests. Its default round-robin strategy makes it straightforward to distribute traffic across multiple backends.

Leave a Comment

Your email address will not be published.