PHP code example of greensight / laravel-phprdkafka-producer

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

    

greensight / laravel-phprdkafka-producer example snippets


use Greensight\LaravelPhpRdKafkaProducer\HighLevelProducer;

(new HighLevelProducer($topicName))->sendOne($messageString);

(new HighLevelProducer($topicName))->sendMany([$message1String, $message2String]);


use Greensight\LaravelPhpRdKafkaProducer\HighLevelProducer;
use Greensight\LaravelPhpRdKafkaProducer\Exceptions\KafkaProducerException;

$producer = new HighLevelProducer(
    topicName: $topicName, 
    producerName: 'some-producer-from-greensight/laravel-phprdkafka-config', 
    flushTimeout: 5000, // ms
    flushRetries: 5,
);

try {
    $producer
        ->setFlushTimeout(10000)
        ->setFlushRetries(10)
        ->sendOne($messageString);
} catch (KafkaProducerException $e) {
    //...
}