PHP code example of codin / thumper

1. Go to this page and download the library: Download codin/thumper 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/ */

    

codin / thumper example snippets


$connection = new PhpAmqpLib\Connection\AMQPLazyConnection('localhost', '5672', 'username', 'password');
$exchange = new Codin\Thumper\Config\Exchange('my-exchange-name', PhpAmqpLib\Exchange\AMQPExchangeType::DIRECT);

$producer = new Codin\Thumper\Producer($connection, $exchange);
$producer->publish('some message');

$connection = new PhpAmqpLib\Connection\AMQPLazyConnection('localhost', '5672', 'username', 'password');
$exchange = new Codin\Thumper\Config\Exchange('my-exchange-name', PhpAmqpLib\Exchange\AMQPExchangeType::DIRECT);

$queue = new Codin\Thumper\Config\Queue('my-queue-name');
$options = new Codin\Thumper\Config\Consumer($exchange, $queue);

$consumer = new Codin\Thumper\Consumer($connection, $options);

$callback = static function (PhpAmqpLib\Message\AMQPMessage $message): void {
    echo $message->getBody(); // some message
    $message->ack();
};
$consumer->consume($callback);