0

I am using this PHP Kafka client library. Our Kafka is installed on server A and producer from different servers adding data in this using Java code, and now I am trying to consume data via PHP from server B. I need to pass the username and password to access data but in documentation, I am not getting any way to pass the username, password, and bootstrap server.

Java team using following details to add data in kafka

spring.kafka.bootstrap-servers=<value-here>
spring.kafka.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='<username>' password='<password>';

Now same, I am trying to achieve via PHP. How I can pass these parameters with my PHP code to consume data.

Jass
  • 3,345
  • 3
  • 24
  • 41
  • PHP doesn't use JAAS. Look at the librdkafka C library documentation for SASL properties and credentials and use `RdKafka\Conf::set` – OneCricketeer Apr 26 '22 at 13:58

2 Answers2

0

According to the documentation, try to do:

<?php

$conf = new \RdKafka\Conf();
$conf->set('sasl.jaas.config', "org.apache.kafka.common.security.plain.PlainLoginModule   required username='<username>' password='<password>'");
$conf->set('security.protocol', "SASL_SSL");
$conf->set('sasl.mechanism', "PLAIN");
$consumer = new \RdKafka\Consumer($conf);
$consumer->addBrokers("<kafka_servers_list>");
Gal Shaboodi
  • 744
  • 1
  • 7
  • 25
0

Following is the solution of problem.

$conf = new RdKafka\Conf();
$conf->set('bootstrap.servers', '<pass-server-here>'); 
$conf->set('sasl.username', '<username>');
$conf->set('sasl.password', '<password>');
$conf->set('security.protocol', 'sasl_ssl');
$conf->set('sasl.mechanism', 'PLAIN');
$conf->set('group.id', 'anygroupID');
$conf->set('debug', 'all');
$rk = new RdKafka\Consumer($conf);
Jass
  • 3,345
  • 3
  • 24
  • 41