使用php rdkafka發(fā)送消息需要以下步驟:
pecl install rdkafka
<?php
$conf = new RdKafka\Conf();
$conf->set('metadata.broker.list', 'broker1:9092,broker2:9092');
$producer = new RdKafka\Producer($conf);
$topic = $producer->newTopic("test-topic");
$topic->produce(RD_KAFKA_PARTITION_UA, 0, 'Hello, Kafka!');
$producer->poll(0);
$producer->flush(10000); //10秒超時(shí)
以上就是使用php rdkafka發(fā)送消息的基本步驟??梢愿鶕?jù)需要對(duì)發(fā)送消息的參數(shù)進(jìn)行定制化配置。