PHP code example of kain / simplify-amqp

1. Go to this page and download the library: Download kain/simplify-amqp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kain / simplify-amqp example snippets


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...
});

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','');
});