PHP code example of vrnvgasu / php-rabbit-handler

1. Go to this page and download the library: Download vrnvgasu/php-rabbit-handler 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/ */

    

vrnvgasu / php-rabbit-handler example snippets


$connection = new Connection('localhost', 5672, 'guest', 'guest');

$queue = new Queue('hello', false, false, false, false);

$exchange = new Exchange('direct_logs', 'direct', false, false, false);

$binding = new Binding();

$binding = new Binding('key');

$helper = new AMQPHelper($connection, $queue, $exchange, $binding);

$consume = new Consume('', false, false,false, false);

$consume = new Consume('', false, false, false, false, function($msg) {
    print_r('Message: ' . $msg->body);
});

class TestConsumer extends Consumer
{
    /**
     * @param AMQPMessage $msg
     */
    public function callback(AMQPMessage $msg): void
    {
        print_r(' [x] Received ' . $msg->body . "\n");

        if (!$this->consume->getNoAck()) {
            $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
        }
    }
}

$consumer = new Consumer($helper, $publication);

$consumer->execute();

$seconds = 60;
$consumer->execute(true, null, false, $seconds);

$publication = new Publication([], 'hello');

$producer = new Producer($helper, $consume);

$producer->execute(TestJob::dispatch($param));

TestJob::dispatch($param)->execute($producer);

use ATC\Jobs\TestJob;

TestJob::dispatch($param1, $param2, $param3);

class TestJob extends BaseJob
{
    //
}

    protected function handle($param1, $param2, $param3)
    {
        // Parameters will be passed to this class automatically
        // You can do something with them and get some $data
        
        // In the same method, you need to transfer the payload to the method `payload` for `producer`
        $this->setPayload($data);
    }