[rabbitmq-discuss] PHP Client libraries

Alexandre Kalendarev akalend at mail.ru
Tue Feb 9 11:00:07 GMT 2010


Hi Dieter,

> thank you for your reply. Am I right, the module does not support 
> consuming messages? 

The module is support Consume and Get methods. But Consume 
methods is sync and GET is async.

If You use the  the consume in the WEB pages, the HTTP protocol is async and You can't wait if you have not commet technology.
My recomendation  is use the series of GET method:

// get queue items
$queue = new AMQPQueue(APMQConection(), 'my_queue');
$i=0;
$res = true;
while ($res = $queue->get() !== false  ){
    $i++;
    echo "$i : {$res['msg']}<br>\n";
}

But, You can use the Consume, You must the read queue lenght and make Consume of len messages. 
It is guarantie of absent waiting new messages.


// consume
$i=0;
$queue = new AMQPQueue(APMQConection());

$n = $queue->declare('my_queue');  // we get the lenght of queue
   
$queueMessages = $queue->consume( $n ); // we reading $n messages,  all queue.
foreach($queueMessages as $item){
  $i++;
  echo "$i.$item";
}

If $n less lenght of queue, the all nonreaded messages will be gone.

The Consume method is faster.

>Or Am i mixing up the Modules?
the module php-amqp  http://code.google.com/p/php-amqp/   don't support consume, bind and queue. It is only publish.

If You have any questions send me, I will very happeness ask You. Sorry for my English.

Alexandre




More information about the rabbitmq-discuss mailing list