class AMQPQueue (View source)

stub class representing AMQPQueue from pecl-amqp

Methods

__construct(AMQPChannel $channel)

Create an instance of an AMQPQueue object.

void
ack(int $deliveryTag, int|null $flags = null)

Acknowledge the receipt of a message.

bool
bind(string $exchangeName, string|null $routingKey = null, array $arguments = [])

Bind the given queue to a routing key on an exchange.

bool
cancel(string $consumer_tag = '')

Cancel a queue that is already bound to an exchange and routing key.

void
consume(callable $callback = null, int|null $flags = null, string|null $consumerTag = null)

Consume messages from a queue.

int
declareQueue()

Declare a new queue on the broker.

int
declare()

Declare a new queue on the broker.

int
delete(int $flags = AMQP_NOPARAM)

Delete a queue from the broker.

get(int $flags = null)

Retrieve the next message from the queue.

int
getFlags()

Get all the flags currently set on the given queue.

string|null
getName()

Get the configured name.

bool
nack(int $deliveryTag, int $flags = AMQP_NOPARAM)

Mark a message as explicitly not acknowledged.

bool
reject(int $deliveryTag, int|null $flags = null)

Mark one message as explicitly not acknowledged.

void
recover(bool $requeue = true)

Recover unacknowledged messages delivered to the current consumer.

int
purge()

Purge the contents of a queue.

bool|int|float|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp
getArgument(string $argumentName)

Get the argument associated with the given key.

void
setArgument(string $argumentName, bool|int|float|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp $argumentValue)

Set a queue argument.

void
removeArgument(string $argumentName)

Set a queue argument.

void
setArguments(array $arguments)

Set all arguments on the given queue.

array
getArguments()

Get all set arguments as an array of key/value pairs.

bool
hasArgument(string $argumentName)

Check whether a queue has specific argument.

bool
setFlags(int|null $flags = null)

Set the flags on the queue.

bool
setName(string $name)

Set the queue name.

bool
unbind(string $exchangeName, string|null $routingKey = null, array $arguments = [])

Remove a routing key binding on an exchange from the given queue.

getChannel()

Get the AMQPChannel object in use

getConnection()

Get the AMQPConnection object in use

string|null
getConsumerTag()

Get latest consumer tag. If no consumer available or the latest on was canceled null will be returned.

Details

__construct(AMQPChannel $channel)

Create an instance of an AMQPQueue object.

Parameters

AMQPChannel $channel

The amqp channel to use.

Exceptions

AMQPQueueException
AMQPConnectionException

void ack(int $deliveryTag, int|null $flags = null)

Acknowledge the receipt of a message.

This method allows the acknowledgement of a message that is retrieved without the AMQP_AUTOACK flag through AMQPQueue::get() or AMQPQueue::consume()

Parameters

int $deliveryTag

The message delivery tag of which to acknowledge receipt.

int|null $flags

The only valid flag that can be passed is AMQP_MULTIPLE.

Return Value

void

Exceptions

AMQPChannelException
AMQPConnectionException

bool bind(string $exchangeName, string|null $routingKey = null, array $arguments = [])

Bind the given queue to a routing key on an exchange.

Parameters

string $exchangeName

Name of the exchange to bind to.

string|null $routingKey

Pattern or routing key to bind with.

array $arguments

Additional binding arguments.

Return Value

bool

Exceptions

AMQPChannelException
AMQPConnectionException

bool cancel(string $consumer_tag = '')

Cancel a queue that is already bound to an exchange and routing key.

Parameters

string $consumer_tag

The consumer tag cancel. If no tag provided, or it is empty string, the latest consumer tag on this queue will be used and after successful request it will set to null. If it also empty, no basic.cancel request will be sent. When consumer_tag give and it equals to latest consumer_tag on queue, it will be interpreted as latest consumer_tag usage.

Return Value

bool

Exceptions

AMQPChannelException
AMQPConnectionException

void consume(callable $callback = null, int|null $flags = null, string|null $consumerTag = null)

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.

Parameters

callable $callback

A 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 object from which callback was invoked. The AMQPQueue::consume() will not return the processing thread back to the PHP script until the callback function returns FALSE. If the callback is omitted or null is passed, then the messages delivered to this client will be made available to the first real callback registered. That allows one to have a single callback consuming from multiple queues.

int|null $flags

A bitmask of any of the flags: AMQP_AUTOACK, AMQP_JUST_CONSUME. Note: when AMQP_JUST_CONSUME flag used all other flags are ignored and $consumerTag parameter has no sense. AMQP_JUST_CONSUME flag prevent from sending basic.consume request and just run $callback if it provided. Calling method with empty $callback and AMQP_JUST_CONSUME makes no sense.

string|null $consumerTag

A string describing this consumer. Used for canceling subscriptions with cancel().

Return Value

void

Exceptions

AMQPChannelException
AMQPConnectionException
AMQPEnvelopeException
AMQPQueueException

int declareQueue()

Declare a new queue on the broker.

Return Value

int

the message count.

Exceptions

AMQPChannelException
AMQPConnectionException
AMQPQueueException

int declare()

Declare a new queue on the broker.

Return Value

int

the message count.

Exceptions

AMQPChannelException
AMQPConnectionException
AMQPQueueException

int delete(int $flags = AMQP_NOPARAM)

Delete a queue from the broker.

This includes its entire contents of unread or unacknowledged messages.

Parameters

int $flags

Optionally AMQP_IFUNUSED can be specified to indicate the queue should not be deleted until no clients are connected to it.

Return Value

int

The number of deleted messages.

Exceptions

AMQPChannelException
AMQPConnectionException

AMQPEnvelope|null get(int $flags = null)

Retrieve the next message from the queue.

Retrieve the next available message from the queue. If no messages are present in the queue, this function will return NULL immediately. This is a non blocking alternative to the AMQPQueue::consume() method. Currently, the only supported flag for the flags parameter is AMQP_AUTOACK. If this flag is passed in, then the message returned will automatically be marked as acknowledged by the broker as soon as the frames are sent to the client.

Parameters

int $flags

A bitmask of supported flags for the method call. Currently, the only the supported flag is AMQP_AUTOACK. If this value is not provided, it will use the value of ini-setting amqp.auto_ack.

Return Value

AMQPEnvelope|null

Exceptions

AMQPChannelException
AMQPConnectionException
AMQPQueueException

int getFlags()

Get all the flags currently set on the given queue.

Return Value

int

An integer bitmask of all the flags currently set on this exchange object.

string|null getName()

Get the configured name.

Return Value

string|null

The configured name as a string.

bool nack(int $deliveryTag, int $flags = AMQP_NOPARAM)

Mark a message as explicitly not acknowledged.

Mark the message identified by delivery_tag as explicitly not acknowledged. This method can only be called on messages that have not yet been acknowledged, meaning that messages retrieved with by AMQPQueue::consume() and AMQPQueue::get() and using the AMQP_AUTOACK flag are not eligible. When called, the broker will immediately put the message back onto the queue, instead of waiting until the connection is closed. This method is only supported by the RabbitMQ broker. The behavior of calling this method while connected to any other broker is undefined.

Parameters

int $deliveryTag

Delivery tag of last message to reject.

int $flags

AMQP_REQUEUE to requeue the message(s), AMQP_MULTIPLE to nack all previous unacked messages as well.

Return Value

bool

Exceptions

AMQPChannelException
AMQPConnectionException

bool reject(int $deliveryTag, int|null $flags = null)

Mark one message as explicitly not acknowledged.

Mark the message identified by delivery_tag as explicitly not acknowledged. This method can only be called on messages that have not yet been acknowledged, meaning that messages retrieved with by AMQPQueue::consume() and AMQPQueue::get() and using the AMQP_AUTOACK flag are not eligible.

Parameters

int $deliveryTag

Delivery tag of the message to reject.

int|null $flags

AMQP_REQUEUE to requeue the message(s).

Return Value

bool

Exceptions

AMQPChannelException
AMQPConnectionException

void recover(bool $requeue = true)

Recover unacknowledged messages delivered to the current consumer.

Recover all the unacknowledged messages delivered to the current consumer. If $requeue is true, the broker can redeliver the messages to different consumers. If $requeue is FALSE, it can only redeliver it to the current consumer. RabbitMQ does not implement $request = false. This method exposes basic.recover from the AMQP spec.

Parameters

bool $requeue

If TRUE, deliver to any consumer, if FALSE, deliver to the current consumer only

Return Value

void

Exceptions

AMQPConnectionException
AMQPChannelException

int purge()

Purge the contents of a queue.

Returns the number of purged messages

Return Value

int

Exceptions

AMQPChannelException
AMQPConnectionException

bool|int|float|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp getArgument(string $argumentName)

Get the argument associated with the given key.

Parameters

string $argumentName

The key to look up.

Return Value

bool|int|float|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp

Exceptions

AMQPQueueException

void setArgument(string $argumentName, bool|int|float|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp $argumentValue)

Set a queue argument.

Parameters

string $argumentName

The key to set.

bool|int|float|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp $argumentValue

The argument value to set.

Return Value

void

void removeArgument(string $argumentName)

Set a queue argument.

Parameters

string $argumentName

The argument name to set.

Return Value

void

void setArguments(array $arguments)

Set all arguments on the given queue.

All other argument settings will be wiped.

Parameters

array $arguments

An array of name/value pairs of arguments.

Return Value

void

array getArguments()

Get all set arguments as an array of key/value pairs.

Return Value

array

An array containing all the set key/value pairs.

bool hasArgument(string $argumentName)

Check whether a queue has specific argument.

Parameters

string $argumentName

The argument name to check.

Return Value

bool

bool setFlags(int|null $flags = null)

Set the flags on the queue.

Parameters

int|null $flags

A bitmask of flags: AMQP_DURABLE, AMQP_PASSIVE, AMQP_EXCLUSIVE, AMQP_AUTODELETE.

Return Value

bool

bool setName(string $name)

Set the queue name.

Parameters

string $name

The name of the queue.

Return Value

bool

bool unbind(string $exchangeName, string|null $routingKey = null, array $arguments = [])

Remove a routing key binding on an exchange from the given queue.

Parameters

string $exchangeName

The name of the exchange on which the queue is bound.

string|null $routingKey

The binding routing key used by the queue.

array $arguments

Additional binding arguments.

Return Value

bool

Exceptions

AMQPChannelException
AMQPConnectionException

AMQPChannel getChannel()

Get the AMQPChannel object in use

Return Value

AMQPChannel

AMQPConnection getConnection()

Get the AMQPConnection object in use

Return Value

AMQPConnection

string|null getConsumerTag()

Get latest consumer tag. If no consumer available or the latest on was canceled null will be returned.

Return Value

string|null