The Runtime features a native client mechanism that allows to load balance requests to the runtimes and supports failover, using the startCommand utility of Stambia Runtime
In this scenario, requests will be automatically redirected to one of the defined Runtimes which is available.
Prerequisites:
- Stambia DI Runtime S17.4.0 or higher
Configuration
All the cluster configuration is done in a file named client.xml
that must be created under the <stambiaRuntime>/properties/ folder.
A file sample is available under the <stambiaRuntime>/properties/samples/client/ folder.
The content of this file looks like this:
<client connectionTimeout="3000"> <connection name="cluster" retry="2" delay="1"> <!-- Main Load Balanced 3 nodes --> <runtime host="localhost" port="42000" priority="0" user="admin" uncryptedPassword="admin"/> <runtime host="localhost" port="43000" priority="0" /> <runtime host="localhost" port="44000" priority="0" /> <!-- Failover Load Balanced 3 nodes --> <runtime host="localhost" port="45000" priority="1" /> <runtime host="localhost" port="46000" priority="1" /> <runtime host="localhost" port="47000" priority="1" /> <!-- The load balancing strategy. For the moment, only the 'random' strategy is supported--> <property name="loadBalancing.strategy" value="random"/> </connection> </client>
Important:
- This a client system and it will not configure, start, or prepare automatically any Runtime.
- This feature is used only to connect and load balance the request to one of the defined Runtime, that must be configured, prepared and started independently.
- "startcommand.bat" command should be restarted to take into account the update of "client.xml" file.
The connection node
The main connection node is used to define the cluster name and retry behavior.
The syntax is the following:
<connection name="cluster name" retry="number of retry" delay="retry delay">
</connection>
The following attributes are available:
Attribute | Description |
name | Name of the Runtime cluster. This is important as this is the name that must be used to connect to the cluster. |
retry | When the cluster fails to connect to a Runtime (including the failover nodes), it will try again the amount of time specified in this attribute. |
delay | Time, in milliseconds, to wait between each retry. |
The Runtime node
You can define as many "runtime" node as required, and the syntax is the following:
<runtime host="localhost" port="42000" priority="0" user="runtimeUser" password="encrypted password" uncryptedPassword="plain text password"/>
The following attributes are available:
Attribute | Is Mandatory | Description |
host | yes | Hostname of the Runtime. |
port | yes | Port of the Runtime. |
priority | yes | Priority of the Runtime. The cluster tries to connect first to one of the Runtime nodes with the highest priority (0 being the highest). If it is not available, it will try to access to a node with a lower priority recursively. |
user | no | User of the Runtime |
password | no |
User's encrypted password. The password must be encrypted with the Runtime's encrypt command. |
uncryptedPassword | no | User's uncrypted password. |
You can have multiple Runtime nodes with the same priority.
In this case the cluster will load balance the requests to one of them with the strategy defined.
The property node
The property node is used to manage the cluster behavior and the syntax is the following:
<property name="property name" value="value"/>
The following properties are available:
Name | Possible values | Description |
loadBalancing.strategy | random |
The load balancing strategy used to choose a node. |
Connecting to a cluster
The client.xml being set, we can now connect to our newly created cluster of Runtime.
- Launch the startcommand.bat (or. sh) utility that is located in the <stambiaRuntime>/ folder
- Connect to the cluster with the
connect to <cluster nume>
Runtime command
Example of output:
> connect to cluster
Connecting to cluster
Connecting to localhost on port 42000
Connection failed
Fallback to lower priority Runtime
Connecting to localhost on port 46000
Connected
You can see here that the connection is redirected automatically to the Runtime on port 46000 after having failed to connect to the one on port 42000.
Schedule with a cluster
We can also set a schedule for our newly created Runtime cluster.
- Launch the startcommand.bat (or. sh) utility that is located in the <stambiaRuntime>/ folder
- Connect
- Set the scheduler with the
schedule delivery on host <cluster nume>
Runtime command
Example:
>schedule delivery My_Deliv on host cluster cron "0 15 10 * * ? *"
Note there is another way to sharing delivery schedules between runtimes
Refer to this article for further information