/** * Resync invalid offsets to the first valid position * * @return integer Number of partitions/broker resync'ed */ public function resyncOffsets() { $nReset = 0; foreach ($this->iterators as $it) { $consumer = new SimpleConsumer($it->host, $it->port, $this->socketTimeout, $this->maxBatchSize); try { $newOffset = $it->offset + $it->uncommittedOffset; $request = new FetchRequest($this->topic, $it->partition, $newOffset, $this->maxBatchSize); $it->messages = $consumer->fetch($request); } catch (Exception\OffsetOutOfRange $e) { $offsets = $consumer->getOffsetsBefore($this->topic, $it->partition, SimpleConsumer::OFFSET_FIRST, 1); if (count($offsets) > 0) { $newOffset = $offsets[0]; $this->offsetRegistry->commit($this->topic, $it->broker, $it->partition, $newOffset); $it->uncommittedOffset = 0; $it->offset = $newOffset; ++$nReset; } } } return $nReset; }