PHP code example of posapp-vn / laravel-kafka-queue

1. Go to this page and download the library: Download posapp-vn/laravel-kafka-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/ */

    

posapp-vn / laravel-kafka-queue example snippets


'connections' => [
    'kafka' => [
        'driver' => 'kafka',
        'brokers' => env('KAFKA_QUEUE_BROKERS', '127.0.0.1:9092'),
        'queue' => env('KAFKA_QUEUE_DEFAULT', 'default'),
        'topic_prefix' => env('KAFKA_QUEUE_TOPIC_PREFIX', 'app.production.queue.'),
        'group_id_prefix' => env('KAFKA_QUEUE_GROUP_PREFIX', 'app.production'),
    ],
],

ReportJob::dispatch($reportId)
    ->onConnection('kafka')
    ->onQueue('default');

public string $connection = 'kafka';

Queue::connection('kafka')->push(new ReportJob($reportId));

ReportJob::dispatch($reportId)->delay(now()->addMinute()); // 

public function backoff(): int
{
    return 30; // retried immediately unless a state store is configured
}

PosAppVN\LaravelKafkaQueue\Contracts\StateStore

'state_store' => App\Queue\DatabaseStateStore::class,
bash
php artisan vendor:publish --tag=kafka-queue-config
bash
php artisan queue:work kafka --queue=high,default