This commit is contained in:
2020-10-28 16:11:19 +08:00
parent b943a7af8a
commit ad43b452af
+8 -12
View File
@@ -42,18 +42,20 @@ class Producer extends Component
private TopicConf $topicConf; private TopicConf $topicConf;
public function __construct($config = [])
{
$this->conf = Snowflake::createObject(Conf::class);
$this->topicConf = Snowflake::createObject(TopicConf::class);
parent::__construct($config);
}
/** /**
* @param $servers * @param $servers
* @return Producer * @return Producer
* @throws NotFindClassException
* @throws ReflectionException
*/ */
public function setBrokers(string $servers) public function setBrokers(string $servers)
{ {
if (!$this->conf) {
/** @var Conf $conf */
$this->conf = Snowflake::createObject(Conf::class);
}
$this->conf->set('metadata.broker.list', $servers); $this->conf->set('metadata.broker.list', $servers);
return $this; return $this;
} }
@@ -62,15 +64,9 @@ class Producer extends Component
/** /**
* @param bool $value * @param bool $value
* @return $this * @return $this
* @throws NotFindClassException
* @throws ReflectionException
*/ */
public function setAck(bool $value) 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); $this->topicConf->set('request.required.acks', (int)$value);
return $this; return $this;
} }