PHP code example of larva / laravel-queue-kafka

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

    

larva / laravel-queue-kafka example snippets


// config/app.php

'providers' => [
    '...',
    Larva\Queue\Kafka\KafkaServiceProvider::class,
];

        'kafka' => [
            /*
             * Driver name
             */
            'driver' => 'kafka',
            /*
             * The name of default queue.
             */
            'queue' => env('KAFKA_QUEUE', 'default'),
            /*
             * The group of where the consumer in resides.
             */
            'consumer_group_id' => env('KAFKA_CONSUMER_GROUP_ID', 'laravel_queue'),
            /*
             * Address of the Kafka broker
             */
            'brokers' => env('KAFKA_BROKERS', 'localhost'),
            /*
             * Determine the number of seconds to sleep if there's an error communicating with kafka
             * If set to false, it'll throw an exception rather than doing the sleep for X seconds.
             */
            'sleep_on_error' => env('KAFKA_ERROR_SLEEP', 5),
            /*
             * Sleep when a deadlock is detected
             */
            'sleep_on_deadlock' => env('KAFKA_DEADLOCK_SLEEP', 2),
            
            /*
             * 全局默认配置
             */
            'defaultConf' => [
                'enable.auto.commit' => 'false',
                'offset.store.method' => 'broker',
                //'security.protocol' => 'SASL_SSL',
                //'sasl.mechanisms' => 'PLAIN',
                //'sasl.username' => '',
                //'sasl.password' => '',
                //'ssl.ca.location' => '/ca-cert.pem',
            ]
        ],

    'default' => 'kafka'