phpapache-kafkalibrdkafka

PHP with Kafka - rdkafka


Iam dealing with kafka and php, Im beginner the kafka has been set upped correctly on the server,

now am on local I have installed: librdkafka.dll on xamp/php and php_rdkafka.dll on xamp/php/ext

and i added this on php.ini:

extension=php_rdkafka.dll

then, i have created a php page contains this code:

$topic_name = '???';
$conf = new RdKafka\Conf();
$conf->set('metadata.broker.list', $broker_list);
$conf->set('enable.idempotence', 'true');
$conf->set('group.id', $topic_name);
$conf->set('sasl.username', "???");
$conf->set('sasl.mechanism', "PLAIN");
$conf->set('sasl.password', "???");
$conf->set('log_level', (string) LOG_DEBUG);
$conf->set('debug', 'all');
$producer = new RdKafka\Producer($conf);
$producer->addBrokers($broker_list);
$topic = $producer->newTopic($topic_name);
$topic->produce(RD_KAFKA_PARTITION_UA, 0, "Message Test");
$producer->poll(0);
$result = $producer->flush(10000);

but nothing returns on stream


Solution

  • Are you trying to connect to confluent cloud?

    I would add to your conf your security protocol, as you indicate sasl. eg $conf->set('security.protocol','sasl_ssl');

    I would think you would not need to indicate the brokers in the producer, as you have already done this in the config. I am presuming your broker list is a csv formatted file that include host and port number?