(PECL amqp >= Unknown)
AMQPQueue::consume — Consume messages from a queue
Blocking function that will retrieve the next message from the queue as it becomes available and will pass it off to the callback.
callbackA callback function to which the consumed message will be passed. The function must accept at a minimum one parameter, an AMQPEnvelope object, and an optional second parameter the AMQPQueue from which the message was consumed.
The AMQPQueue::consume() will not return the processing thread back to the PHP script until the callback function returns FALSE.
flags
A bitmask of any of the flags: AMQP_NOACK.
Throws AMQPChannelException if the channel is not open.
Throws AMQPConnectionException if the connection to the broker was lost.
Example #1 AMQPQueue::consume() example
<?php
/* Create a connection using all default credentials: */
$connection = new AMQPConnection();
$connection->connect();
$channel = new AMQPChannel($connection);
/* create a queue object */
$queue = new AMQPQueue($channel);
//declare the queue
$queue->declare('myqueue');
$i = 0;
function processMessage($envelope, $queue) {
global $i;
echo "Message $i: " . $envelope->getBody() . "\n";
$i++;
if ($i > 10) {
// Bail after 10 messages
return false;
}
}
// Consume messages on queue
$queue->consume("processMessage");
?>