Saturday 19 September 2015

RabbitMQ: Fair dispatching of messages to consumers

As I said RabbitMQ dispatches messages equally to consumers using Round Robbin algorithm. Suppose consider this scenario, where there is one producer and two consumers C1, C2. Unfortunately consumer C1 is getting more overloaded tasks and C2 is getting less overloaded tasks. In this case, we have to  maintain load balance properly.

How to solve above problem?
We can solve above problem by using basicQos method with the prefetchCount = 1 setting.

int prefetchCount = 1;
channel.basicQos(prefetchCount);
This statement tells RabbitMQ that don't dispatch a new message to a consumer until it has processed and acknowledged the previous one. Instead, it will dispatch it to the next worker that is not still busy.



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment