PHP code example of adspray / rabbitmq-management-client

1. Go to this page and download the library: Download adspray/rabbitmq-management-client 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/ */

    

adspray / rabbitmq-management-client example snippets



use RabbitMQ\Management\AsyncAPIClient;
use React\EventLoop\Factory;

$loop = Factory::create();

$client = AsyncAPIClient::factory($loop, array(
    'url'      => '127.0.0.1',
));

$loop->addPeriodicTimer(1, function () use ($client) {
    $client->listQueues()
        ->then(function($queues) {
            echo "\n------------\n";
            foreach ($queues as $queue) {
                echo sprintf("Found queue %s with %d messages\n", $queue->name, $queue->messages);
            }
        }, function ($error) {
            echo "An error occured : $error\n";
        });
});

$loop->run();

use RabbitMQ\Management\APIClient;
use RabbitMQ\Management\Entity\Queue;
use RabbitMQ\Management\Exception\EntityNotFoundException;

$client = APIClient::factory(array('url'=>'localhost'));

try {
    $queue = $client->getQueue('/', 'queue.leuleu');

    if (true !== $queue->durable) {
        $queue->durable = true;

        $client->deleteQueue('/', 'queue.leuleu');
        $client->addQueue($queue);
    }

} catch (EntityNotFoundException $e) {
    $queue = new Queue();
    $queue->vhost = '/';
    $queue->name = 'queue.leuleu';
    $queue->durable = true;

    $client->addQueue($queue);
}

use RabbitMQ\Management\APIClient;
use RabbitMQ\Management\Entity\Queue;
use RabbitMQ\Management\Guarantee;

$client = APIClient::factory(array('url'=>'localhost'));
$manager = new Guarantee($client);

$queue = new Queue();
$queue->vhost = '/';
$queue->name = 'queue.leuleu';
$queue->durable = true;
$queue->auto_delete = false;

$queue = $manager->ensureQueue($queue);