MAKS\AmqpAgent\Worker\Consumer
A class specialized in consuming. Implementing only the methods needed for a consumer.
Example:
```
$consumer = new Consumer();
$consumer->connect();
$consumer->queue();
$consumer->qos();
$consumer->consume('SomeNamespace\SomeClass::someCallback');
$consumer->wait();
$consumer->disconnect();
```
Synopsis
- // members
- protected $qosOptions;
- protected $waitOptions;
- protected $consumeOptions;
- protected $ackOptions;
- protected $nackOptions;
- // Inherited members from AbstractWorker
- protected $connectionOptions;
- protected $channelOptions;
- protected $queueOptions;
- public AMQPStreamConnection $connection;
- public AMQPChannel $channel;
- public array $connections;
- public array $channels;
- // methods
- public void __construct()
- public static void ack()
- public static void nack()
- public static ?AMQPMessage get()
- public static mixed cancel()
- public static mixed recover()
- public static void reject()
- public Consumer qos()
- public Consumer consume()
- public bool isConsuming()
- public Consumer wait()
- public Consumer waitForAll()
- public Consumer prepare()
- public void work()
- // Inherited methods from AbstractWorker
- public void __construct()
- public void __destruct()
- public mixed __get()
- public void __set()
- public static bool shutdown()
- public static AMQPTable arguments()
- public AbstractWorker connect()
- public AbstractWorker disconnect()
- public AbstractWorker reconnect()
- public AbstractWorker queue()
- public AMQPStreamConnection|null getConnection()
- public AbstractWorker setConnection()
- public AMQPStreamConnection getNewConnection()
- public AMQPChannel|null getChannel()
- public AbstractWorker setChannel()
- public AMQPChannel|null getNewChannel()
- public AMQPChannel|null getChannelById()
- // Inherited methods from MagicMethodsExceptionsTrait
- public void __get()
- public void __set()
- public mixed __call()
- public static mixed __callStatic()
- // Inherited methods from WorkerMutationTrait
- protected array mutateClassMember()
- protected array mutateClassSubMember()
- // Inherited methods from WorkerCommandTrait
- public static array makeCommand()
- public static bool isCommand()
- public static bool hasCommand()
- public static mixed getCommand()
Hierarchy
Extends
Implements
Coverage
Methods | 92.86% | 13 / 14 |
Lines | 99.28% | 138 / 139 |
Members
protected
- $ackOptions
—
array
The full acknowledgment options that should be used for the worker. - $channelOptions
—
array
The default channel options that the worker should use when no overrides are provided. - $connectionOptions
—
array
The default connection options that the worker should use when no overrides are provided. - $consumeOptions
—
array
The full consume options that should be used for the worker. - $mutation
—
array
The last mutation happened to a class member (for debugging purposes). - $nackOptions
—
array
The full unacknowledgment options that should be used for the worker. - $qosOptions
—
array
The full quality of service options that should be used for the worker. - $queueOptions
—
array
The default queue options that the worker should use when no overrides are provided. - $waitOptions
—
array
The full wait options that should be used for the worker.
public
- $channel
—
PhpAmqpLib\Channel\AMQPChannel
The default channel of the worker. - $channels
—
array
All opened channels of the the worker. - $commandPrefix
—
string
The prefix that should be used to define an array as a command. - $commandSyntax
—
array
The recommended way of defining a command array. - $connection
—
PhpAmqpLib\Connection\AMQPStreamConnection
The default connection of the worker. - $connections
—
array
All opened connections of the worker.
Methods
public
- __construct() — Consumer object constructor.
- ack() — Acknowledges an AMQP message object.
- cancel() — Ends a queue consumer.
- consume() — Consumes messages from the default channel of the worker's connection to RabbitMQ server.
- get() — Gets a message object from a channel, direct access to a queue.
- isConsuming() — Checks whether the default channel is consuming.
- nack() — Unacknowledges an AMQP message object.
- prepare() — Executes `self::connect()`, `self::queue()`, and `self::qos()` respectively (note that `self::wait()` needs to be executed after `self::consume()`).
- qos() — Specifies the quality of service on the default channel of the worker's connection to RabbitMQ server.
- recover() — Redelivers unacknowledged messages
- reject() — Rejects an AMQP message object.
- wait() — Keeps the connection to RabbitMQ server alive as long as the default channel is in used.
- waitForAll() — Tries to keep the connection to RabbitMQ server alive as long as there are channels in used (default or not).
- work() — Executes `self::connect()`, `self::queue()`, `self::qos()`, `self::consume()`, `self::wait()`, and `self::disconnect()` respectively.
Inherited from MAKS\AmqpAgent\Worker\AbstractWorker
public
- __get() — Gets a class member via public property access notation.
- __set() — Sets a class member via public property assignment notation.
- arguments() — Returns an AMQPTable object.
- connect() — Establishes a connection with RabbitMQ server and opens a channel for the worker in the opened connection, it also sets both of them as defaults.
- disconnect() — Closes all open channels and connections with RabbitMQ server.
- getChannel() — Returns the default channel of the worker. If the worker is not connected, it returns null.
- getChannelById() — Fetches a channel object identified by the passed id (channel_id). If not found, it returns null.
- getConnection() — Returns the default connection of the worker. If the worker is not connected, it returns null.
- getNewChannel() — Returns a new channel on the the passed connection of the worker. If no connection is passed, it uses the default connection. If the worker is not connected, it returns null.
- getNewConnection() — Opens a new connection to RabbitMQ server and returns it. Connections returned by this method pushed to connections array and are not set as default automatically.
- queue() — Declares a queue on the default channel of the worker's connection with RabbitMQ server.
- reconnect() — Executes `self::disconnect()` and `self::connect()` respectively. Note that this method will not restore old channels.
- setChannel() — Sets the passed channel as the default channel of the worker.
- setConnection() — Sets the passed connection as the default connection of the worker.
- shutdown() — Closes the connection or the channel or both with RabbitMQ server.
Inherited from MAKS\AmqpAgent\Exception\MagicMethodsExceptionsTrait
public
- __call() — Throws an exception for calls to undefined methods.
- __callStatic() — Throws an exception for calls to undefined static methods.
- __get() — Throws an exception when trying to get a class member via public property assignment notation.
- __set() — Throws an exception when trying to set a class member via public property assignment notation.
Inherited from MAKS\AmqpAgent\Worker\WorkerMutationTrait
protected
- mutateClassMember() — Mutates a subset of an array (class property) and returns the replaced subset.
- mutateClassSubMember() — Mutates a subset of an array inside a class property (nested array inside a property) and returns the replaced subset.
Inherited from MAKS\AmqpAgent\Worker\WorkerCommandTrait
public
- getCommand() — Returns the content of a specific key in the command array, used for example to get the additional parameters.
- hasCommand() — Checks whether a specific command (command name) exists in the command array.
- isCommand() — Checks whether an array is a command following the recommended pattern.
- makeCommand() — Constructs a command from passed data to a command array following the recommended pattern.
History
-
2021-08-28T07:40:51+00:00 (commit #7ac0060)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update consumer class * Update work() method implemenation * Update consume() method to shut down all opened channels and connections * Fix some typos in DocBlocks
-
2021-01-12T21:10:22+00:00 (commit #9f59177)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update consumer class * Remove return value type hint "self" from methods signature due to unexpected behavior with different PHP versions
-
2021-01-12T21:10:22+00:00 (commit #720a4c6)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update consumer class * Change nack() method signature * Fix typos * Update DocBlocks
-
2021-01-12T21:10:21+00:00 (commit #e4c5a83)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update consumer class * Fix some coding style issues
-
2021-01-12T21:10:21+00:00 (commit #d09424b)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Add strict types declaration * Add declare(strict_types=1) to all files * Fix file header DocBlock spacing of all files
-
2020-09-25T20:19:17+00:00 (commit #e9812cd)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Refactor consumer class * Make use of the newly created ConsumerParameters class * Make use of the newly created MagicMethodsExceptionsTrait * Update the class in different places to make use of the new additions
-
2020-09-23T19:26:04+00:00 (commit #cd6ed4f)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Remove PHPUnit annotations * Remove @codeCoverageIgnore annotations from the workers
-
2020-09-23T18:47:06+00:00 (commit #1a3f203)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Fix typos and update DocBlocks * Fix some typos in DockBlocks and other parts of the codebase * Add examples to classes DocBlocks
-
2020-09-13T23:00:41+00:00 (commit #0044405)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Fix php-amqplib v2.12.0 deprecations * Fix references to deprecated properties in php-amqplib v2.12.0
-
2020-06-15T00:19:37+00:00 (commit #8cc2ffb)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update consumer class * Add disconnect() to work() method * Update work() method docblock
-
2020-06-13T05:52:30+00:00 (commit #6e2cb57)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Implementing the consumer * Add Consumer.php * Add CallbackDoesNotExistException.php