改名
This commit is contained in:
+14
-2
@@ -5,6 +5,7 @@ namespace Kafka;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use RdKafka\Conf;
|
use RdKafka\Conf;
|
||||||
|
use RdKafka\ProducerTopic;
|
||||||
use RdKafka\TopicConf;
|
use RdKafka\TopicConf;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Abstracts\Component;
|
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)
|
private function push($message, $key)
|
||||||
{
|
{
|
||||||
$topic = $this->producer->newTopic($this->_topic, $this->topicConf);
|
if(!isset($this->topics[$this->_topic])){
|
||||||
$topic->produce(RD_KAFKA_PARTITION_UA, 0, $message, $key);
|
$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);
|
$this->producer->poll(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user