faaren-tech / kafka-client
Simple Kafka Wrapper
Installs: 206
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/faaren-tech/kafka-client
Requires
- flix-tech/avro-serde-php: ~1.4
- jobcloud/php-kafka-lib: ~1.4
This package is auto-updated.
Last update: 2023-10-10 19:06:00 UTC
README
This package offers a simple Kafka-Client-Wrapper with Laravel Facades and configs
Installation
Run the following commands:
// Install the package
composer require faaren-tech/kafka-client
// Publish config
php artisan vendor:publish --provider="FaarenTech\KafkaClient\KafkaClientServiceProvider"
Configuration Parameter
The parameters are prepared and needs to be added to your .env
FAA_KAFKA_REGISTRY_URL=XXXX
FAA_KAFKA_REGISTRY_AUTH_USER=XXXX
FAA_KAFKA_REGISTRY_AUTH_PASSWORD=XXXX
FAA_KAFKA_BROKER_URL=XXXX
FAA_KAFKA_BROKER_AUTH_USER=XXXX
FAA_KAFKA_BROKER_AUTH_PASSWORD=XXXX
FAA_KAFKA_CONSUMER_GROUP_ID=XXXX
Producer
Producer::topic('TopicName') ->buildProducerWithRegistry('BodySchema', 'KeySchema') ->message('KeyValue', 'Data2Send', 'headers', 'partition') ->produce(); Producer::flush();
Consumer
$consumer = Consumer::topic('TopicName') ->buildConsumerWithRegistry('BodySchema', 'KeySchema') ->subscribe(); while(true) { /** * First Parameter, is the Timeout in ms, Second Parameter is the Auto-Decode Option */ $consumer->consume(5000, false, function($consumer, $message){ //to "commit" the message, please use the ack method $consumer->ack($message); }); }