Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

How can I create topic with kafka-php programming library? #315

Open
nicolapaganotti1 opened this issue Mar 15, 2022 · 0 comments
Open

How can I create topic with kafka-php programming library? #315

nicolapaganotti1 opened this issue Mar 15, 2022 · 0 comments

Comments

@nicolapaganotti1
Copy link

Hi, I want create a topic with kafka-php programming library. How can I do?

If topic doesn't exist in kafka server, executing this code, it doesn't work. It doesn't insert 10 messages "test1....message." because topic isn't create.

date_default_timezone_set('PRC');
// Create the logger
$logger = new Logger('my_logger');
// Now add some handlers
$logger->pushHandler(new StreamHandler(DIR . '/app.log', Logger::DEBUG));

$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('127.0.0.1:9092');
$config->setBrokerVersion('1.0.0');
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer();
$producer->setLogger($logger);

for($i = 0; $i < 10; $i++) {
$result = $producer->send([
[
'topic' => 'test1',
'value' => 'test1....message.',
'key' => ''
]
]);
}

exit;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant