PHPRdfKafka而不是创建新主题如何产生到现有主题中



一个简单的问题,我正在使用php-rdkafka(https://github.com/arnaud-lb/php-rdkafka(冒险进入Kafka。

我浏览了文档,除非语法 newTopic 将插入到我怀疑的现有主题中,否则我找不到要生成到现有主题中的语法。我一直遇到 Java 错误,我不擅长调试 Java 错误。我正在向那些一直在使用该框架的人寻求帮助,它是正确的语法吗?请指教

<?php
$conf = new RdKafkaConf();
$conf->set('metadata.broker.list', 'localhost:9092');
//If you need to produce exactly once and want to keep the original produce order, uncomment the line below
//$conf->set('enable.idempotence', 'true');
$producer = new RdKafkaProducer($conf);
$topic = $producer->newTopic("test"); // Is this a correct syntax to consume existing topic?
for ($i = 0; $i < 10; $i++) {
$topic->produce(RD_KAFKA_PARTITION_UA, 0, "Message $i");
$producer->poll(0);
}
for ($flushRetries = 0; $flushRetries < 10; $flushRetries++) {
$result = $producer->flush(10000);
if (RD_KAFKA_RESP_ERR_NO_ERROR === $result) {
break;
}
}
if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
throw new RuntimeException('Was unable to flush, messages might be lost!');
}

根据与开发人员的讨论,

以下语法可用于创建新主题并将数据添加到以下/现有主题

$topic = $producer->newTopic("test"); /

相关内容

最新更新