在网上看到有几种发送消息的方法
1, 其中,在 php-rdkafka-doc 文档中有写到使用:
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!');
}
由 poll -> flush
然后看到网上有朋友说 flush会造成严重堵塞问题;但是说能保证数据完整性
2, 在其他朋友笔记记录
for($i = 0; $i < 100; $i++) {
$producer->send([
[
'topic' => 'test1',
'value' => 'test1....message.',
'key' => '',
],
]);
}
现在有个问题就是:这二种写法之间,如何选择? 哪个更可靠