Skip to main content
Version: 8.2405.x.x RR

Use a third-party load balancer

If you want to use a third party loadbalancer you can do this with a LuaFilter and a dynamic backend configuration in the Http(s)ConnectorServlet. The idea of this approach is that the LuaFilter script does a side call to a third party loadbalancer to get the backend to connect. This is done once per session to have session stickiness. The following proposed LuaFilter script is only an example how this can be achieved and not a ready to use solution, as the script depends highly on your loadbalancer and your purpose. The example does not include error handling in case the third party loadbalancer is down or sends back error codes. In such a case you may want a default backend or react with some kind of response toward the client.

The following LuaFilter snippet is just a base to start with, adjust this script to your need.

<filter>
<filter-name>LuaFilterTest</filter-name>
<filter-class>ch::nevis::isiweb4::filter::lua::LuaFilter</filter-class>
<init-param>
<param-name>Script.InputHeaderFunctionName</param-name>
<param-value>inputHeader</param-value>
</init-param>
<init-param>
<param-name>Script</param-name>
<param-value>
function inputHeader(req, resp)
local session = req:getSession(true)
local backend = session:getAttribute("bcx.servlet.selected.backend");
if not backend then
local reqCall = nevis.filter.lua.request.new()
local respCall = nevis.filter.lua.response.new()
local dispatcher = req:getDispatcher("SideCallServlet")
dispatcher:forward(reqCall, respCall)
session:setAttribute("bcx.servlet.selected.backend", respCall:getBody());
end
end
</param-value>
</init-param>
</filter>

Furthermore, you need a dispatcher servlet which does not need any servlet mapping.

    <servlet>
<servlet-name>SideCallServlet</servlet-name>
<servlet-
class>ch::nevis::isiweb4::servlet::connector::http::HttpConnectorServlet</servlet-class>
<init-param>
<param-name>InetAddress</param-name>
<param-value>:</param-value>
</init-param>
<init-param>
<param-name>ResourceManager.RetryTimeout</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>ResourceManager.DisablePing</param-name>
<param-value>true</param-value>
</init-param>
</servlet>

And last, you need a special configured backend connector.

    <servlet>
<servlet-name>HttpConnectorServlet</servlet-name>
<servlet-
class>ch::nevis::isiweb4::servlet::connector::http::HttpConnectorServlet</servlet-class>
<init-param>
<param-name>InetAddress</param-name>
<param-value>SESSION:bcx.servlet.selected.backend;</param-value>
</init-param>
<init-param>
<param-name>ResourceManager.RetryTimeout</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>ResourceManager.DisablePing</param-name>
<param-value>true</param-value>
</init-param>
</servlet>

Look at the InetAddress parameter that is the link between the LuaFilter script and the chosen backend. The servlet just gets the backend from the session.