PHP code example of quellabs / canvas-scheduler-rabbitmq

1. Go to this page and download the library: Download quellabs/canvas-scheduler-rabbitmq 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/ */

    

quellabs / canvas-scheduler-rabbitmq example snippets


return [
    'queue_driver' => 'rabbitmq',
];

$queue = $container->for('rabbitmq')->get(QueueInterface::class);

return [
    'host'           => '127.0.0.1',
    'port'           => 5672,
    'user'           => 'guest',
    'password'       => 'guest',
    'vhost'          => '/',
    'queue_name'     => 'default',
    'exchange_name'  => '',
    'queue_max_jobs' => 500,
    'prefetch_count' => 1,
];

use Quellabs\Contracts\Scheduler\QueueableInterface;

class SendEmailJob implements QueueableInterface {

    public function __construct(
        private int    $userId,
        private string $template
    ) {}

    public function handle(): void {
        // Send the email
    }

    public function getPayload(): array {
        return [
            'userId'   => $this->userId,
            'template' => $this->template,
        ];
    }

    public function getTimeout(): int {
        return 30;
    }

    public function getMaxRetries(): int {
        return 3;
    }
}

use Quellabs\Contracts\Scheduler\QueueInterface;

class UserController {

    public function __construct(private QueueInterface $queue) {}

    public function register(Request $request): Response {
        // Handle registration...

        $this->queue->push(new SendEmailJob(
            userId: $user->id,
            template: 'welcome'
        ));

        return new Response('Registered');
    }
}