PHP 7.4 AMQP library
Documentation powered by Read the Docs.
PHP 7.4+ AMQP libray supporting multiple drivers and providing full-featured Consumer, Producer, and JSON-RPC Client / Server implementations.
The JSON-RPC part implements JSON-RPC 2.0 Specification.
Current supported drivers are: php-amqp and PhpAmqpLib.
php-amqp needs at least to be v1.9.3 php-amqplib needs at least to be v3
This library ships with psr/container
factories that help you setting up everything.
You can install prolic/humus-amqp via composer by adding "prolic/humus-amqp": "^2.0"
as requirement to your composer.json.
$exchangeName = 'test-exchange';
$exchange = ExchangeFactory::$exchangeName($container);
$exchange->publish('test-message');
$queueName = 'test-queue';
$queue = QueueFactory::$queueName($container);
$message = $queue->get();
$queue->ack($message->getDeliveryTag());
$producerName = 'test-producer';
$producer = ProducerFactory::$producerName($container);
$producer->confirmSelect();
$producer->publish(['foo' => 'bar'], 'my-routing-key');
$producer->waitForConfirm();
$clientName = 'my-client';
$client = JsonRpcClientFactory::$clientName($container);
$client->addRequest(new JsonRpcRequest('my-server', 'method', ['my' => 'params'], 'id-1'));
$client->addRequest(new JsonRpcRequest('my-server', 'method', ['my' => 'other_params'], 'id-2'));
$responseCollection = $client->getResponseCollection();
$serverName = 'my-server';
$server = JsonRpcServerFactory::$serverName($container);
$server->consume();
Before: If auto_setup_fabric
was enabled, the queue and exchange binding was done automatically. The exchanges would also get created. Anonymous queues required to have auto_setup_fabric
set to true.
New: If auto_setup_fabric
is enabled or the queue is anonymous (has no name), the queue gets created and binding is done, but no exchanges are created. If you want to enable creating of depending exchanges (including exchange binding), set the new argument auto_setup_exchanges
to true.
This is a slight BC break, but the old behaviour was so problematic, that I had to make this change either way.
- We recommend using php-amqp >=v1.9.3 or compiling it from master, if you encounter any problems with the amqp extension, check their issue tracker, first.
The ext-amqp driver is the most performant.
-
When using php-amqplib as driver, it's worth point out, that a StreamConnection (same goes for SSLConnection) does not have the possibility to timeout. If you want to let the consumer timeout, when no more messages are received, you should use the SocketConnection instead (assuming you don't need an SSL connection).
-
When using php-amqplib as driver and you're using the LazyConnection, you should not create the channel yourself, call instead
$channel = $connection->newChannel()
- File issues at https://github.com/prolic/HumusAmqp/issues.
- Say hello in the HumusAmqp gitter chat.
Please feel free to fork and extend existing or add new plugins and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and may adapt the documentation.
Released under the MIT.