PHP code example of nepster-web / php-simple-queue

1. Go to this page and download the library: Download nepster-web/php-simple-queue 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/ */

    

nepster-web / php-simple-queue example snippets


$transport = new \Simple\Queue\Transport\DoctrineDbalTransport($connection);

$config = \Simple\Queue\Config::getDefault()
    ->registerProcessor('my_queue', static function(\Simple\Queue\Context $context): string {
        // Your message handling logic
        return \Simple\Queue\Consumer::STATUS_ACK;
    });
    
$producer = new \Simple\Queue\Producer($transport, $config);

$message = $producer->createMessage('my_queue', ['key' => 'value']);

$producer->send($message);

$config = \Simple\Queue\Config::getDefault()
    ->registerJob(MyJob::class, new MyJob());

$producer = new \Simple\Queue\Producer($transport, $config);

$producer->dispatch(MyJob::class, ['key' => 'value']);

$producer = new \Simple\Queue\Producer($transport, $config);
$consumer = new \Simple\Queue\Consumer($transport, $producer, $config);

$consumer->consume();

php composer.phar 

"nepster-web/php-simple-queue": "*"