Wednesday, May 26, 2010

MSMQ load balancing

Microsoft does not recommend load balancing MSMQ, the reason has to do with the level of security demanded via the RPC protocol with MSMQ. The read operation will not be able to make the connection to MSMQ and will be dropped by the receiver. There are no workarounds since this would compromise the security of the connection. However, If you are really desperate to load balance the MSMQ here is one possible architecture.

In order to perform load balancing you will need to distribute the write load among the MSMQ's you have. in order to do this you will need to use a hardware load balancer like F5-BigIp

If you have two MSMQ machines then your writer application will write half of the messages to the first MSMQ and the other half to the second MSMQ. your reader application however can not use the load balancer to do the read. since this read will be a remote read which will be stopped by RPC protocol, your reader applications should be local to the MSMQ. In the diagram below


The writer application writes to the load balancer, the load balancer distributes the messages and check the health of the MSMQ server before sending a message to it. In case one of the MSMQ servers is taken down the load balancer will only forward the traffic to the active MSMQ. which should achieve your load balance and fail-over requirement. You can also add a third or fourth MSMQ to the cluster if you encounter higher load and you want to scale your architecture up. you can also take MSMQ down and your application will not be aware since it always communicate with the load balaner.

For the read operation; Typically MSMQ reading is most efficient when done locally. Having multiple readers on each local machine would provide fault-tolerance along with higher performance. That said, you should have the reader application installed directly on the MSMQ machines. This way the reader applications are performing a local read which will not compromise the RPC security. Your reader application can then process the MSMQ message do whatever it needs to do like sending the contents in email or saving to a database or whatever it is supposed to do.