public function consumeStart($partition, $offset = RD_KAFKA_OFFSET_BEGINNING) { if (true === $this->isConsuming) { throw new \Exception("This topic is already consuming"); } if (!$this->consumerTopic) { throw new \Exception("Could not start consuming because no kafka consumer is available"); } $this->consumerTopic->consumeStart($partition, $offset); $this->isConsuming = true; }
public function consume($partition) { if (!$this->consumers) { throw new \Exception("Topic " . $this->name . " has no registered consumers"); } if (!$this->rdKafkaConsumerTopic) { throw new \Exception("Topic " . $this->name . " is not registered as consumer topic"); } $this->rdKafkaConsumerTopic->consumeStart($partition, RD_KAFKA_OFFSET_BEGINNING); while ($message = $this->rdKafkaConsumerTopic->consume($partition, 10000)) { foreach ($this->consumers as $consumer) { $consumer->consume($message->topic_name, $message->partition, $message->offset, $message->key, $message->payload); } } $this->rdKafkaConsumerTopic->consumeStop($partition); }