TsgcWebSocketLoadBalancerServer
The component TsgcWebSocketLoadBalancerServer allows you to Load Balancing WebSocket and HTTP Protocols. For websockedt protocol allows you to distributing messages across a group of servers and distributes clients connections using a random sequence or fewer connections algorithm.
The Load Balancer Server, inherits all methods and properties from TsgcWebSocketHTTPServer.
Load Balancer Configuration
The Load Balancer server it's a descendant of TsgcWebSocketHTTPServer, so read the documentation about the TsgcWebSocketHTTPServer to know how to configure it.
Additionally, the Load Balancer has the property LoadBalancer, which has the following properties:
- LoadBalancing: configure here how distribute the connections
- lbRandom: (default) every time a new client request a new connection, it will return a random server.
- lbConnections: every time a new client request a new connection, it will return server with fewer clients connected.
- Protocols: configure which protocols are enabled
- WebSocket: if true, the websocket connections will be handled by the Load Balancer Server.
- HTTP: if true, the http connections will be handled by the Load Balancer Server.
Backup Server Configuration
The Backup Servers (the servers behind the load balancer) can be a TsgcWebSocketServer, TsgcWebSocketHTTPServer or a Datasnap Server.
Those servers have a property called LoadBalancer where you can configure the connection between the LoadBalancer Server and the Backup Servers.
- Enabled: set to true if you want to use as a backup server.
- Host: the host were is the LoadBalancer.
- Port: the listening port of the LoadBalancer.
- Guid: unique id that identifies this server.
- Bindings: the public addresses accessible were the connections will be forwarded. Example: if the Backup WebSocket server is listening on port 8000 and the ip address is 1.1.1.1, use the following: ws://1.1.1.1:8000;
- AutoRegisterBindings: if enabled, the LoadBalancer Server will use the Bindings property of the backup server to configure the public bindings.
- AutoRestart: in seconds, if greater than zero, the load balancer client of the backup server will enable an internal watchdog that every x seconds, will check if the connection is alive, if it's closed, it will try to reconnect.
Events
- OnBeforeSendServerBinding: raised before binding is sent to a new client connection.
- OnClientConnect: every time a client connection is stablished, this event is triggered.
- OnClientDisconnect: every time a client connection is dropped, this event is triggered.
- OnClientMessage: raised when a new text message is received from the server.
- OnClientBinary: raised when a new binary message is received from the server.
- OnClientFragmented: raised when a new fragmented message is received from the server.
- OnServerConnect: raised when a new server connects to LoadBalancerServer.
- OnServerDisconnect: raised when a server disconnects from LoadBalancerServer.
- OnServerReady: raised when a server is ready to accept messages.
- OnLoadBalancerHTTPRequest: the event is called when there is a new HTTP Request and before it's forwarded to a backup server.
- OnLoadBalancerHTTPResponse: the event is called with the HTTP Response sent by the backup server.