[rabbitmq-discuss] Problem with multiple consumers on multiple servers !

tluck tilak.chauhan at ymail.com
Fri Mar 29 18:57:17 GMT 2013


I've recently started to develop a cron job kind of mechanism by using
rabbitmq. In this system a producer reads all the jobs (messages) from a
database table and creates queues, depending upon the category of the job
and puts jobs into their respective queues. In other words, each job belongs
to a particular category and for each category we've a queue.

Now I've setup multiple consumers and each consumer is listening to a single
queue. Below is the sample code (in PHP) for each consumer :

$connection = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $connection->channel();
$channel->queue_declare('queue_category_1', false, true, false, false);
$channel->exchange_declare('router', 'direct', true, true, false);
$channel->queue_bind('queue_category_1', 'router', 'queue_category_1');

$callback = function($msg)  {  /***** code here to consume message/job
******/  };

$channel->basic_qos(null, 1, null);

$channel->basic_consume('queue_category_1', 'unique_consumer_tag', false,
false, false, false, $callback);

while (count($channel->callbacks)) {

When I try to call all the consumers simultaneously, I can see they all are
consuming/processing messages/jobs parallely. Now I've added one more server
(server-2) which consumes messages from previous sever (server-1). In this
way, now the number of consumers are doubled (server-1 is working as both
producer and consumer sever & server-2 is consumer server). In both the
servers, consumer processes are running parallely, but, they are not
consuming messages as they are supposed to do. The problem which I've
noticed is that only one message/job from each queue is being consumed at a
time. As I added one more server so now two jobs from each queue should be
consumed at time instead of only one job. Soon I'll have to add more severs
to make this system more distributed. Can anyone please help me to find out,
why only one job is being consumed at a time ? and what can be the solution

Thanks in advance.



View this message in context: http://rabbitmq.1065348.n5.nabble.com/Problem-with-multiple-consumers-on-multiple-servers-tp25790.html
Sent from the RabbitMQ mailing list archive at Nabble.com.

More information about the rabbitmq-discuss mailing list