/** * Get an approximate measure of the amount of data still to be consumed * * @return integer */ public function getRemainingSize() { try { if (0 == $this->nIterators) { $this->rewind(); // initialise simple consumers } } catch (Exception\InvalidTopic $e) { $logMsg = 'Invalid topic from ZookeeperConsumer::rewind(): Most likely cause is no topic yet as there is no data'; error_log($logMsg); } $totalSize = 0; foreach ($this->iterators as $it) { $readBytes = $it->offset + $it->uncommittedOffset; if (null !== $it->messages) { $readBytes += $it->messages->validBytes(); } $consumer = new SimpleConsumer($it->host, $it->port, $this->socketTimeout, $this->maxBatchSize); $offsets = $consumer->getOffsetsBefore($this->topic, $it->partition, SimpleConsumer::OFFSET_LAST, 1); if (count($offsets) > 0) { $remaining = $offsets[0] - $readBytes; // remaining bytes for this broker/partition if ($remaining > 0) { $totalSize += $remaining; } } $consumer->close(); } return $totalSize; }