改名
This commit is contained in:
+12
-5
@@ -95,9 +95,6 @@ class Producer extends Component
|
|||||||
if (!$this->conf || !$this->topicConf) {
|
if (!$this->conf || !$this->topicConf) {
|
||||||
throw new \Exception('Error. Please set kafka conf.');
|
throw new \Exception('Error. Please set kafka conf.');
|
||||||
}
|
}
|
||||||
$this->conf->setDrmSgCb(function ($kafka, $message) {
|
|
||||||
// $this->debug(var_export($message, true));
|
|
||||||
});
|
|
||||||
$this->conf->setErrorCb(function ($kafka, $err, $reason) {
|
$this->conf->setErrorCb(function ($kafka, $err, $reason) {
|
||||||
$this->error(sprintf("Kafka error: %s (reason: %s)", rd_kafka_err2str($err), $reason));
|
$this->error(sprintf("Kafka error: %s (reason: %s)", rd_kafka_err2str($err), $reason));
|
||||||
});
|
});
|
||||||
@@ -105,13 +102,23 @@ class Producer extends Component
|
|||||||
/** @var \RdKafka\Producer $rk */
|
/** @var \RdKafka\Producer $rk */
|
||||||
$rk = Snowflake::createObject(\RdKafka\Producer::class, [$this->conf]);
|
$rk = Snowflake::createObject(\RdKafka\Producer::class, [$this->conf]);
|
||||||
if ($rk->getOutQLen() > 0) {
|
if ($rk->getOutQLen() > 0) {
|
||||||
$rk->poll(0);
|
$this->clean($rk, $timeout);
|
||||||
$rk->flush($timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$topic = $rk->newTopic($this->_topic, $this->topicConf);
|
$topic = $rk->newTopic($this->_topic, $this->topicConf);
|
||||||
$topic->produce(RD_KAFKA_PARTITION_UA, 0, $message, $key);
|
$topic->produce(RD_KAFKA_PARTITION_UA, 0, $message, $key);
|
||||||
|
$this->clean($rk, $timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $rk
|
||||||
|
* @param $timeout
|
||||||
|
*/
|
||||||
|
private function clean($rk, $timeout)
|
||||||
|
{
|
||||||
$rk->poll(0);
|
$rk->poll(0);
|
||||||
$rk->flush($timeout);
|
$rk->flush($timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user