1. Go to this page and download the library: Download iamfarhad/laravel-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/ */
// Dispatch a job to the default queue
dispatch(new ProcessPodcast($podcast));
// Dispatch a job to a specific queue
dispatch(new ProcessPodcast($podcast))->onQueue('podcasts');
// Dispatch a job with delay
dispatch(new ProcessPodcast($podcast))->delay(now()->addMinutes(10));
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ProcessPodcast implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(private $podcast)
{
// Specify a custom queue
$this->onQueue('podcasts');
}
public function handle()
{
// Process the podcast...
}
}
$job = (new ProcessPodcast($podcast))->onQueue('podcasts');
dispatch($job->withProperty('priority', 10));
'queue' => [
'qos' => [
'prefetch_size' => 0, // No specific size limit
'prefetch_count' => 10, // Process 10 messages at a time
'global' => false // Apply per consumer, not channel
]
]
// In your job class
public function failed(Throwable $exception)
{
// Handle failed job
}
// Custom retry delay
public function retryAfter()
{
return 30; // seconds
}