set('metadata.broker.list', $servers); return $this; } /** * @param bool $value * @return $this * @throws NotFindClassException * @throws ReflectionException */ public function setAck(bool $value) { /** @var TopicConf $conf */ $conf = Snowflake::createObject(TopicConf::class); $conf->set('request.required.acks', (int)$value); return $this; } /** * @param $servers * @return Producer */ public function setTopic(string $servers) { $this->_topic = $servers; return $this; } /** * @param $message * @param null $key * @param int $timeout * @throws */ public function delivery($message, $key = null, $timeout = 5) { $conf = Snowflake::createObject(Conf::class); $conf->setDrmSgCb(function ($kafka, $message) { // $this->debug(var_export($message, true)); }); $conf->setErrorCb(function ($kafka, $err, $reason) { $this->error(sprintf("Kafka error: %s (reason: %s)", rd_kafka_err2str($err), $reason)); }); $rk = new \RdKafka\Producer(); $topic = $rk->newTopic($this->_topic, Snowflake::createObject(TopicConf::class)); $topic->produce(RD_KAFKA_PARTITION_UA, 0, $message, $key); if ($rk->getOutQLen() > 0) { $rk->poll($timeout); } $rk->flush($timeout); } }