0

I am very new to kafka. I am trying to send a message from my local machine producer to kafka server. I am not able to figure out the issue or what am doing worng.

$config = \Kafka\ProducerConfig::getInstance();
    $config->setMetadataRefreshIntervalMs(10000);
    $config->setMetadataBrokerList('localhost:9092');
    $config->setBrokerVersion('1.0.0');
    $config->setRequiredAck(1);
    $config->setIsAsyn(false);
    $config->setProduceInterval(500);
    $producer = new \Kafka\Producer(
        function() {
            return [
                [
                  'topic' => 'test',
                  'value' => 'test....message.',
                  'key' => 'testkey',
                ],
            ];
        }
    );
    // $producer->setLogger($logger);
    $producer->success(function($result) {
        print_r($result);
    });
    $producer->error(function($errorCode) {
            var_dump($errorCode);
    });
    $producer->send(true);

Output:- Fatal error: Uncaught exception 'Kafka\Exception' with message 'Not has broker can connection metadataBrokerList' in C:\xampp\htdocs\vendor\nmred\kafka-php\src\Kafka\Producer\Process.php on line 193

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
int_ashish
  • 121
  • 1
  • 5

2 Answers2

0

So you're trying to produce from your local machine to a different server? If that's the case you'll need to update the line

$config->setMetadataBrokerList('localhost:9092');

to point to that server's domain name and not localhost:9092

William Hammond
  • 623
  • 4
  • 11
0

This is the library https://github.com/weiboad/kafka-php I was using in codeigniter for the producer. This library works fine. The issue was that on server port number was changed, it was 29092 actually by default the port is 9092 that why the connection was failing.

int_ashish
  • 121
  • 1
  • 5