public function consume($partition, $timeoutInMs = 10000) { if (true !== $this->isConsuming) { throw new \Exception("Please call consumeStart first to start consuming message"); } while ($message = $this->consumerTopic->consume($partition, $timeoutInMs)) { foreach ($this->consumers as $consumer) { $consumer->consume($message->topic_name, $message->partition, $message->offset, $message->key, $message->payload); } } }
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); }