kain / simplify-amqp
This package is abandoned and no longer maintained.
No replacement package was suggested.
Simplify amqp operation library php-amqplib / php-amqplib
2.1
2020-04-29 03:44 UTC
Requires
- php: >=7.4
- ext-json: *
- myclabs/php-enum: ^1.7
- php-amqplib/php-amqplib: ^2.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.2
- phpunit/php-code-coverage: ^7.0
- phpunit/phpunit: ^8
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2021-07-29 02:09:58 UTC
README
Simplify amqp operation library php-amqplib / php-amqplib
Setup
composer require kain/simplify-amqp
Usage
Create an AMQP client
use Simplify\AMQP\AMQPClient; use Simplify\AMQP\AMQPManager; $client = new AMQPClient( 'localhost', 5672, 'guest', 'guest', '/', [ 'insist' => false, 'login_method' => 'AMQPLAIN', 'login_response' => null, 'locale' => 'zh_CN', 'connection_timeout' => 5.0, 'read_write_timeout' => 5.0, 'context' => null, 'keepalive' => true, 'heartbeat' => 3.0, 'channel_rpc_timeout' => 5.0, 'ssl_protocol' => null ] ); $client->channel(function (AMQPManager $manager) { // operate... });
Create exchange and queue, and then bind them together
use Simplify\AMQP\AMQPClient; use Simplify\AMQP\AMQPManager; use Simplify\AMQP\Common\ExchangeCreateOption; use Simplify\AMQP\Common\ExchangeType; use Simplify\AMQP\Common\QueueCreateOption; $client = new AMQPClient('localhost',5672,'guest','guest'); $client->channel(function (AMQPManager $manager) { $exchangeOption = new ExchangeCreateOption(); $exchangeOption->setType(ExchangeType::DIRECT()); $exchangeOption->setDurable(true); $manager->exchange('myexchange')->create($exchangeOption); $queueOption = new QueueCreateOption(); $queueOption->setDurable(true); $queueOption->setMaxLength(3000); $queueOption->setMaxLengthBytes(1024*64); $queue = $manager->queue('myqueue'); $queue->create($queueOption); $queue->bind('myexchange',''); });
For more examples, please see unit testing