/** * set topic partition * * @access public * @param $topicName * @param int $partitionId * @param null $offset * @return Consumer */ public function setPartition($topicName, $partitionId = 0, $offset = null) { if (is_null($offset)) { if ($this->fromOffset) { $offsetObject = new \Kafka\Offset($this->client, $this->group, $topicName, $partitionId); $offset = $offsetObject->getOffset($this->offsetStrategy); \Kafka\Log::log('topic name:' . $topicName . ', part:' . $partitionId . 'get offset from kafka server, offet:' . $offset, LOG_DEBUG); } else { $offset = 0; } } $this->payload[$topicName][$partitionId] = $offset; return $this; }
/** * set topic partition * * @access public * @return void */ public function setPartition($topicName, $partitionId = 0, $offset = null) { if (is_null($offset)) { if ($this->fromOffset) { $offsetObject = new \Kafka\Offset($this->client, $this->group, $topicName, $partitionId); $offset = $offsetObject->getOffset(\Kafka\Offset::DEFAULT_EARLY); } else { $offset = 0; } } $this->payload[$topicName][$partitionId] = $offset; return $this; }
/** * get consumer offset for a specific topic & partition * */ public function getOffset($topicName, $partitionId = 0) { $offsetObject = new \Kafka\Offset($this->client, $this->group, $topicName, $partitionId); $offset = $offsetObject->getOffset(\Kafka\Offset::DEFAULT_EARLY); return $offset; }