I installed
"nmred/kafka-php": "0.2.*"
this package, the following is the official code
<?php
require "vendor/autoload.php";
date_default_timezone_set("PRC");
$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList("192.168.83.50:9092");
$config->setBrokerVersion("1.1.0");
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer();
$result = $producer->send(array(
array(
"topic" => "test",
"value" => "test1....message.",
"key" => "",
),
));
var_dump($result);
first of all, I started the producer and consumer on the terminal. If the message is available to the consumer, there should be no problem with starting the service.
php code feedback result is failure, for some reason