/** * @param string $topic * @param ConsumerConfiguration|null $consumerConfiguration * @return ConsumerTopicFacade */ public function createConsumerTopicFacade($topic, ConsumerConfiguration $consumerConfiguration = null) { if (null === $consumerConfiguration) { $consumerConfiguration = new ConsumerConfiguration(); } if (null === $this->rdKafkaConsumer) { $this->rdKafkaConsumer = $this->createConsumer(); } return new ConsumerTopicFacade($this->rdKafkaConsumer->newTopic($topic, $consumerConfiguration->toRdKafkaTopicConfig())); }
/** * @param $topic * @param null $offset * @param int $count * @param array $configs * @return Message */ public function consume($topic, $offset = null, $count = 0, $configs = []) { $offset = null !== $offset ? $offset : RD_KAFKA_OFFSET_BEGINNING; $partition = isset($configs['partition']) ? $configs['partition'] : RD_KAFKA_PARTITION_UA; /** @var ConsumerTopic $topic */ $topic = $this->consumer->newTopic($topic, isset($configs['topic']) ? $configs['topic'] : null); $this->start($topic, $partition, $offset); $message = $this->getQueue()->consume($partition, $count); if ($message->err) { throw new ConsumerException($message->errstr()); } return new Message($message->payload, \DateTime::createFromFormat("U", time()), null); }
/** * @return ConsumerTopic */ private function buildConsumerTopic() { $consumer = new Consumer(); $consumer->addBrokers(self::BROKER); return $consumer->newTopic(self::TOPIC); }