释放双眼,带上耳机,听听看~!
1
2
3
4
5
6
7
8
9
10
11
12
13 1$conf = new \RdKafka\Conf();
2//捕获错误的回调
3$conf->setErrorCb(function ($kafka, $err, $reason) {
4 \Log::error('kafkaError', ['errorStr' => rd_kafka_err2str($err), 'err' => $err, 'reason' => $reason, 'content' => $kafka]);
5});
6$rk = new \RdKafka\Producer($conf);
7$rk->setLogLevel(LOG_DEBUG);
8$rk->addBrokers($this->url);
9$topic = $rk->newTopic($this->topic);
10//写kafka
11$topic->produce(RD_KAFKA_PARTITION_UA, 0, $str);
12$rk->poll(0);
13