In the previous example we set up a load balancer with 3 nodes. We used a Web interface to register nodes with the balancer. Now we will use an API and clients to register nodes.
In this example we will use a simple client to communicate with the API to manage nodes. We also encrypt the parameters that are sent.
To run the example execute the following steps:
-
Go to the
examples/loadbalancing/3-clientdirectory. -
Run
membrane.cmdormembrane.shThis will start three nodes, the loadbalancer and the node management API.
-
Open the URL http://localhost:4000/ in your browser.
You will see a simple web app that counts how often it was called. There are 2 more endpoints of the same kind listening at port
4001and4002. However, it is possible that it will count twice a single connection, due to the browser checking for the favicon. -
Register a node on
localhoston port4000by running thelbclient.sh/batscript.lbclient.sh up localhost 4000 -
Open the Admin Web console.
http://localhost:9000/admin -
Click on the "Load Balancing" tab. Then click on the link called "Default". On the next page, again click on "Default".
-
You will find there the node you registered with the lbclient.
-
Register 2 additional nodes:
lbclient.sh up localhost 4001lbclient.sh up localhost 4002 -
Send a request to the loadbalancer:
http://localhost:8080 -
Click the refresh button in your browser a few times. You will notice that requests will be distributed to node 1 to 3.
-
Put a node off:
lbclient.sh down localhost 4000 -
Open
http://localhost:8080again. After several refreshes, you will notice that no request are directed to node 1 anymore.
-
First stop the router by closing the command line that runs the router e.g. by using CTRL-C.
-
Execute
service-proxy-secured.batorservice-proxy-secured.sh -
Execute
lbclient.sh up localhost 4000The parameters are not encrypted, so the operation fails.
-
Open the file
client.properties -
Remove the # from the following line:
#key=6f488a642b740fb70c5250987a284dc0 -
Execute
lbclient.bat up localhost 4000This time the parameters are encrypted.
-
Open http://localhost:9000/admin/clusters/show?cluster=Default
-
Login with admin/admin and notice the node you just added.
Of course, you can protect the management API like any other Membrane proxy using SSL, a password or token.
See:
- balancer reference