trueifnotfalse / lumen-kafka
Kafka driver for Lumen Queue.
Installs: 1 297
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0 || ^8.1
- mateusjunges/laravel-kafka: ^1.7
README
Installation
Install the package via composer
composer require trueifnotfalse/lumen-kafka
Then you should register the service provider in bootstrap/app.php
$app->register(TrueIfNotFalse\LumenKafka\Providers\KafkaServiceProvider::class);
Configuration
Add to config/queue.php
:
... '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, ], ...
MonitoringHandler::class
<?php 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()); } }
Consumer
Run
php artisan kafka:consume monitoring