TsgcWebSocketLoadBalancerServer › Properties › LoadBalancer
Configures how the load balancer distributes downstream connections across registered backends and which protocols are balanced.
property LoadBalancer: TsgcWSLoadBalancer_Options read FLoadBalancer write SetLoadBalancer;
LoadBalancing=lbRandom, Protocols.WebSocket=True, Protocols.HTTP=True
On TsgcWebSocketLoadBalancerServer the LoadBalancer property controls the runtime behaviour of the load balancer itself — it does not configure a client that registers against another load balancer (that role belongs to the same-named property on TsgcWebSocketServer). Backend TsgcWebSocketServer instances register by enabling their own LoadBalancer.Enabled and pointing LoadBalancer.Host/LoadBalancer.Port at this component; registration data is tracked internally in ServerList.
Sub-properties:
LoadBalancing — distribution algorithm used to pick a backend when a new downstream client connects:
lbRandom (default) returns a random registered backend.lbConnections returns the backend with the fewest currently connected clients (least-connections).Protocols.WebSocket — when True, WebSocket connections are handled by the load balancer.Protocols.HTTP — when True, plain HTTP requests are forwarded to a backend (use the OnLoadBalancerHTTPRequest/OnLoadBalancerHTTPResponse events to inspect or mutate the request/response pair).The binding that is returned to a new downstream client is whatever the chosen backend advertised through its own LoadBalancer.Bindings; the OnBeforeSendServerBinding event lets you override the selection just before it is sent.
oServer := TsgcWebSocketLoadBalancerServer.Create(nil);
oServer.Port := 80;
oServer.LoadBalancer.LoadBalancing := lbConnections;
oServer.LoadBalancer.Protocols.WebSocket := true;
oServer.LoadBalancer.Protocols.HTTP := true;
oServer.Active := true;