1. Go to this page and download the library: Download siberfx/apache-kafka 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/ */
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(public int $podcastId)
{
}
public function handle(): void
{
// ... do the work
}
}
use App\Jobs\ProcessPodcast;
// dispatched to the default topic (KAFKA_QUEUE)
ProcessPodcast::dispatch($podcast->id);
// or to a specific topic
ProcessPodcast::dispatch($podcast->id)->onQueue('podcasts');
use Illuminate\Support\Facades\Queue;
Queue::connection('kafka')->push(new ProcessPodcast($podcast->id), '', 'podcasts');