PHP code example of trueifnotfalse / lumen-kafka

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

    

trueifnotfalse / lumen-kafka example snippets


$app->register(TrueIfNotFalse\LumenKafka\Providers\KafkaServiceProvider::class);

...
    'monitoring' => [
        'driver' => 'kafka',
        'brokers' => env('KAFKA_BROKERS', 'localhost'),
        'topics' => ['monitoring'],
        'group_id' => env('KAFKA_GROUP_ID', 'group'),
        'security_protocol' => env('KAFKA_SECURITY_PROTOCOL', 'PLAINTEXT'),
        'sasl' => [
            'username' => env('KAFKA_SASL_USERNAME'),
            'password' => env('KAFKA_SASL_PASSWORD'),
            'mechanisms' => env('KAFKA_SASL_MECHANISMS'),
        ],
        'handler' => MonitoringHandler::class,
    ],
...



namespace App\Handlers;

use Junges\Kafka\Contracts\KafkaConsumerMessage;

class MonitoringHandler
{
    /**
     * @param KafkaConsumerMessage $message
     *
     * @return void
     */
    public function __invoke(KafkaConsumerMessage $message): void
    {
        print_r($message->getBody());
    }
}

bash
php artisan kafka:consume monitoring