MAKS\AmqpAgent\RPC\ServerEndpoint
A class specialized in responding. Implementing only the methods needed for a server.
Example:
```
$serverEndpoint = new ServerEndpoint();
$serverEndpoint->on('some.event', function () { ... });
$serverEndpoint->connect();
$serverEndpoint->respond('Namespace\SomeClass::someMethod', 'queue.name');
$serverEndpoint->disconnect();
```
Synopsis
- // members
- protected callable $callback;
- // Inherited members from AbstractEndpoint
- protected $connectionOptions;
- protected $queueName;
- protected bool $connected;
- protected AMQPStreamConnection $connection;
- protected AMQPChannel $channel;
- protected $requestBody;
- protected $requestQueue;
- protected $responseBody;
- protected $responseQueue;
- protected $correlationId;
- // methods
- public string respond()
- public string serve()
- protected void onRequest()
- protected string callback()
- // Inherited methods from AbstractEndpoint
- public void __construct()
- public void __destruct()
- public AbstractEndpoint connect()
- public void disconnect()
- public bool isConnected()
- public AMQPStreamConnection getConnection()
- public final float ping()
- public final AbstractEndpoint on()
- protected abstract string callback()
- // Inherited methods from MagicMethodsExceptionsTrait
- public void __get()
- public void __set()
- public mixed __call()
- public static mixed __callStatic()
- // Inherited methods from EventTrait
- protected static void trigger()
- protected static void bind()
- public static array getEvents()
Hierarchy
Coverage
Methods | 100% | 4 / 4 |
Lines | 100% | 50 / 50 |
Members
protected
- $callback
—
MAKS\AmqpAgent\RPC\callable
The callback to use when processing the requests. - $channel
—
PhpAmqpLib\Channel\AMQPChannel
The endpoint channel. - $connected
—
MAKS\AmqpAgent\RPC\bool
Whether the endpoint is connected to RabbitMQ server or not. - $connection
—
PhpAmqpLib\Connection\AMQPStreamConnection
The endpoint connection. - $connectionOptions
—
array
The connection options of the RPC endpoint. - $correlationId
—
string
Correlation ID of the last request/response. - $events
—
array
Here lives all bindings. - $queueName
—
string
The queue name of the RPC endpoint. - $requestBody
—
string
The request body. - $requestQueue
—
string
Requests conveyor. - $responseBody
—
string
The response body. - $responseQueue
—
string
Responses conveyor.
Methods
protected
- callback() — Returns the final request body. This method will be ignored if a callback in `self::respond()` is specified.
- onRequest() — Replies to the client.
public
- respond() — Listens on requests coming via the passed queue and processes them with the passed callback.
- serve() — Listens on requests coming via the passed queue and processes them with the passed callback.
Inherited from MAKS\AmqpAgent\RPC\AbstractEndpoint
protected
- callback() — Hook method to manipulate the message (request/response) when extending the class.
public
- connect() — Opens a connection with RabbitMQ server.
- disconnect() — Closes the connection with RabbitMQ server.
- getConnection() — Returns the connection used by the endpoint.
- isConnected() — Returns whether the endpoint is connected or not.
- on() — Hooking method based on events to manipulate the request/response during the endpoint/message life cycle.
- ping() — The time needed for the round-trip to RabbitMQ server in milliseconds.
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\Helper\EventTrait
protected
- bind() — Binds the passed function to the passed event.
- trigger() — Executes callbacks attached to the passed event with the passed arguments.
public
- getEvents() — Returns array of all registered events as an array `['event.name' => [$cb1, $cb2, ...]]`.
History
-
2021-01-12T21:10:22+00:00 (commit #623b9b4)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update server endpoint class * Update DocBlocks
-
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-12-03T21:49:10+00:00 (commit #1dc0c19)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Update client endpoint interface * Add a missing use statement * Change some properties names to match parent class * Add type castings to some unexpected return values from php-amqplib
-
2020-12-02T23:00:54+00:00 (commit #2d7ebfa)
Author: Marwan Al-Soltany (MarwanAlsoltany@gmail.com) / Commiter: Marwan Al-Soltany (MarwanAlsoltany@gmail.com)
Add server endpoint class * Add ServerEndpoint.php