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

This package is auto-updated.

Last update: 2021-07-29 02:09:58 UTC


README

Simplify amqp operation library php-amqplib / php-amqplib

Packagist Version Travis (.org) Coveralls github PHP from Packagist Packagist License

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