/**
  * @return ProducerTopic
  */
 private function buildProducerTopic()
 {
     $producer = new Producer();
     $producer->addBrokers(self::BROKER);
     /** @var ProducerTopic $producerTopic */
     $producerTopic = $producer->newTopic(self::TOPIC);
     $producerTopic->produce(self::PARTITION, 0, 'initial message for a topic creation');
     return $producerTopic;
 }
示例#2
0
 public function setUp()
 {
     $producer = new Producer();
     $producer->addBrokers('localhost:9092');
     if (method_exists($producer, 'getMetadata')) {
         $this->metadata = $producer->getMetadata(true, null, 1000);
     } else {
         $this->metadata = $producer->metadata(true, null, 1000);
     }
 }
示例#3
0
 public function produce($topic, $payload, $configs = [])
 {
     $partition = isset($configs['partition']) ? $configs['partition'] : RD_KAFKA_PARTITION_UA;
     if (isset($configs['config'])) {
         $topic = $this->producer->newTopic($topic, $configs['config']);
     } else {
         $topic = $this->producer->newTopic($topic);
     }
     $topic->produce($partition, 0, $payload);
 }
示例#4
0
 /**
  * @param ProducerConfiguration|null $producerConfiguration
  * @return ProducerTopicFacade
  */
 public function createProducerTopicFacade($topic, ProducerConfiguration $producerConfiguration = null)
 {
     if (null === $producerConfiguration) {
         $producerConfiguration = new ProducerConfiguration();
     }
     if (null === $this->rdKafkaProducer) {
         $this->rdKafkaProducer = $this->createProducer();
     }
     return new ProducerTopicFacade($this->rdKafkaProducer->newTopic($topic, $producerConfiguration->toRdKafkaTopicConfig()));
 }
示例#5
0
 /**
  *
  * @param ClusterMetadataInterface|null $clusterMetadata
  * @param \RdKafka\Conf|null            $config
  */
 public function __construct(ClusterMetadataInterface $clusterMetadata = null, \RdKafka\Conf $config = null)
 {
     if (empty($config)) {
         $config = new \RdKafka\Conf();
     }
     if (!empty($clusterMetadata)) {
         $brokers = $clusterMetadata->getBrokers();
         $brokers = array_map(function ($broker) {
             return sprintf('%s:%d', $broker['host'], $broker['port']);
         }, $brokers);
         $config->set('metadata.broker.list', implode(',', $brokers));
     }
     parent::__construct($config);
 }