From ad43b452af53ebe777c0332d30927f8c35268434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 28 Oct 2020 16:11:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Kafka/Producer.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Kafka/Producer.php b/Kafka/Producer.php index c8d49f0f..e213710e 100644 --- a/Kafka/Producer.php +++ b/Kafka/Producer.php @@ -42,18 +42,20 @@ class Producer extends Component private TopicConf $topicConf; + public function __construct($config = []) + { + $this->conf = Snowflake::createObject(Conf::class); + $this->topicConf = Snowflake::createObject(TopicConf::class); + parent::__construct($config); + } + + /** * @param $servers * @return Producer - * @throws NotFindClassException - * @throws ReflectionException */ public function setBrokers(string $servers) { - if (!$this->conf) { - /** @var Conf $conf */ - $this->conf = Snowflake::createObject(Conf::class); - } $this->conf->set('metadata.broker.list', $servers); return $this; } @@ -62,15 +64,9 @@ class Producer extends Component /** * @param bool $value * @return $this - * @throws NotFindClassException - * @throws ReflectionException */ public function setAck(bool $value) { - if (!$this->topicConf) { - /** @var Conf $conf */ - $this->topicConf = Snowflake::createObject(TopicConf::class); - } $this->topicConf->set('request.required.acks', (int)$value); return $this; }