(PECL amqp >= Unknown)

AMQPQueue::consumeThe consume purpose


public array AMQPQueue::consume ([ array $options = array() ] )

This is a blocking function, in that the function will not return until the minimum number of of messages as specified by the min are read off of the queue. To use a non-blocking function, see



options is a an array of consume options. The keys used in the options array are: min, max, and ack. All other keys will be ignored.

For each missing option, the extension will check the ini settings or use the default value.

Return Values

An array containing the messages consumed. The number of returned messages will be at least the number given by min in the options array. But not more than the number given by max.


Example #1 AMQPQueue::consume() example


/* Create a connection using all default credentials: */
$connection = new AMQPConnection();

/* create a queue object */
$queue = new AMQPQueue($connection);

//declare the queue

$options = array(
'min' => 1,
'max' => 10,
'ack' => true

//get the messages
$messages $queue->consume($options);

foreach (
$messages as $message) {


add a note add a note

User Contributed Notes 1 note

mrxiaosen at 126 dot com
5 months ago
This doc not talk about consumer tag. But the method of consumer,has the third param for consumer tag.
If you want to set the consumer tag,see the example.

$consume_tag = sprintf("%s_%s_%s", php_uname('n'), time(), getmypid());
$queue->consume($callback, \AMQP_NOPARAM, $consume_tag)

public function consume(
        callable $callback = null,
        $flags = AMQP_NOPARAM,
        $consumerTag = null
    ) {}
To Top