Sometimes processing requests on one box is not enough. Single box has limited processing power and when transaction volume is high, you would like to distribute the requests between two or more boxes in a fair manner.
So, the first message (request) that arrives at the broker goes to box 1, second one goes to box 2, third one goes to box 3, fourth goes to box 1, etc.
To implement load balancing create a single queue for the requests and let all the boxes consume from the queue. If there are several consumers on a single queue, messages are automatically distributed between the consumers in round-robin fashion:
Imagine you are running a helpdesk. You have thousands of clients all over the world posting requests and questions all the time. You have several operators who are receiving those requests. You want to have requests load-balanced so that all the requests don't go to a single operator, rather thay are distributed in a fair manner among all the operators. You would also want the system to adapt dynamically, i.e. if an operator closes his application (say going for lunch) the requests are distributed among remaining operators rather than waiting for the absent operator.
You can find implementation of such a helpdesk here:
To compile and link the files set your environment in the same way as you do to build OpenAMQ server and do the following:
$ c -l helpdesk_client.c Compiling helpdesk_client... Linking helpdesk_client... $ c -l helpdesk_operator.c Compiling helpdesk_operator... Linking helpdesk_operator...
To run the helpdesk, you have to start OpenAMQ server first:
Once the server is running you can run the operator terminal this way:
$ ./helpdesk_operator <broker-address>
$ ./helpdesk_operator server001
Clients can connect to the helpdesk in the following way:
$ ./helpdesk_client <broker-address>
$ ./helpdesk_client server001