MAKS\AmqpAgent\Worker\Publisher
A class specialized in publishing. Implementing only the methods needed for a publisher.
Example:
```
$publisher = new Publisher();
$publisher->connect();
$publisher->queue();
$publisher->exchange();
$publisher->bind();
$publisher->publish('Some message!');
$publisher->disconnect();
```
Synopsis
- // members
- protected $exchangeOptions;
- protected $bindOptions;
- protected $messageOptions;
- protected $publishOptions;
- // 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 Publisher exchange()
- public Publisher bind()
- public AMQPMessage message()
- public Publisher publish()
- public Publisher publishBatch()
- public Publisher 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 | 87.5% | 7 / 8 |
Lines | 98.41% | 124 / 126 |
Members
protected
- $bindOptions
—
array
The default bind options that the worker should use when no overrides are provided. - $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. - $exchangeOptions
—
array
The default exchange options that the worker should use when no overrides are provided. - $messageOptions
—
array
The default message options that the worker should use when no overrides are provided. - $mutation
—
array
The last mutation happened to a class member (for debugging purposes). - $publishOptions
—
array
The default publish options that the worker should use when no overrides are provided. - $queueOptions
—
array
The default queue options that the worker should use when no overrides are provided.
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() — Publisher object constructor.
- bind() — Binds the default queue to the default exchange on the default channel of the worker's connection to RabbitMQ server.
- exchange() — Declares an exchange on the default channel of the worker's connection to RabbitMQ server.
- message() — Returns an AMQPMessage object.
- prepare() — Executes `self::connect()`, `self::queue()`, `self::exchange`, and `self::bind()` respectively.
- publish() — Publishes a message to the default exchange on the default channel of the worker's connection to RabbitMQ server.
- publishBatch() — Publishes a batch of messages to the default exchange on the default channel of the worker's connection to RabbitMQ server.
- work() — Executes `self::connect()`, `self::queue()`, `self::exchange`, `self::bind()`, `self::publish()`, 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:33:40+00:00 (commit #72b4b62)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update publisher class * Change publishBatch() method $_exchange parameter to $parameters * Update work() method implemenation * Fix some typos in DocBlocks
-
2021-01-12T21:10:22+00:00 (commit #cd40b96)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update publisher 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 #74b7284)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update publisher class * Change exception type of publish() and publishBatch() methods * Fix typos * Update DocBlocks
-
2021-01-12T21:10:21+00:00 (commit #206cd88)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update publisher 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:16:49+00:00 (commit #62bc03b)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Refactor publisher class * Make use of the newly created PublisherParameters 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-06-15T00:21:34+00:00 (commit #6607062)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update publisher class * Change publishBatch() default exchange name * Update prepare() method docblock * Add disconnect() to work() method * Update work() method docblock
-
2020-06-13T05:51:13+00:00 (commit #031d113)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Implement the publisher * Add WorkerFacilitationInterface.php * Add Publisher.php