This commit is contained in:
2021-02-14 21:29:59 +08:00
parent 294258994b
commit 68e0e82c71
+14 -2
View File
@@ -5,6 +5,7 @@ namespace Kafka;
use Exception;
use RdKafka\Conf;
use RdKafka\ProducerTopic;
use RdKafka\TopicConf;
use ReflectionException;
use Snowflake\Abstracts\Component;
@@ -102,10 +103,21 @@ class Producer extends Component
}
/** @var ProducerTopic[] $topics */
private array $topics = [];
/**
* @param $message
* @param $key
*/
private function push($message, $key)
{
$topic = $this->producer->newTopic($this->_topic, $this->topicConf);
$topic->produce(RD_KAFKA_PARTITION_UA, 0, $message, $key);
if(!isset($this->topics[$this->_topic])){
$this->topics[$this->_topic] = $this->producer->newTopic($this->_topic, $this->topicConf);
}
$this->topics[$this->_topic]->produce(RD_KAFKA_PARTITION_UA, 0, $message, $key);
$this->producer->poll(0);
}