ensi / laravel-phprdkafka-producer
Opiniated High Level producer for laravel-phprdkafka
Installs: 42 364
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 2
Open Issues: 0
Requires
- php: ^8.1
- ext-rdkafka: *
- ensi/laravel-phprdkafka: ^0.4.0
- laravel/framework: ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- nunomaduro/collision: ^6.0 || ^7.0 || ^8.1
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- pestphp/pest: ^1.22 || ^2.0
- pestphp/pest-plugin-laravel: ^1.1 || ^2.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.11
- spaze/phpstan-disallowed-calls: ^2.15
README
Opiniated High Level producer for ensi/laravel-phprdkafka
Installation
Firstly, you have to install and configure ensi/laravel-phprdkafka
Then,
composer require ensi/laravel-phprdkafka-producer
Publish the config file if you need it:
php artisan vendor:publish --provider="Ensi\LaravelPhpRdKafkaProducer\LaravelPhpRdKafkaProducerServiceProvider" --tag="kafka-producer-config"
Version Compatibility
Basic Usage
Send a single message:
use Ensi\LaravelPhpRdKafkaProducer\HighLevelProducer; (new HighLevelProducer($topicKey))->sendOne($messageString);
Send several messages at once:
(new HighLevelProducer($topicKey))->sendMany([$message1String, $message2String]);
All options with defaults:
use Ensi\LaravelPhpRdKafkaProducer\HighLevelProducer; use Ensi\LaravelPhpRdKafkaProducer\Exceptions\KafkaProducerException; $producer = new HighLevelProducer( topicKey: $topicKey, producerName: 'some-producer-from-ensi/laravel-phprdkafka-config', flushTimeout: 5000, // ms flushRetries: 5, ); try { $producer ->setFlushTimeout(10000) ->setFlushRetries(10) ->sendOne($messageString); } catch (KafkaProducerException $e) { //... }
Middleware
You can add middleware globally via config or locally for specific Producer:
$producer->pushMiddleware(SomeMiddleware::class) ->sendOne($messageString);
Middleware example:
use Closure; use Ensi\LaravelPhpRdKafkaProducer\ProducerMessage; class SomeMiddleware { public function handle(ProducerMessage $message, Closure $next): mixed { $message->headers = $message->headers ?: []; $message->headers['Header-Name'] = 'Header Value'; return $next($message); } }
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.