Example #1
0
 /**
  *  Get a list of valid offsets (up to maxSize) before the given time.
  *  The result is a list of offsets, in descending order.
  *
  *  @param time: time in millisecs (-1 from the latest offset available, -2 from the smallest offset available)
  *
  *  @return an array of offsets
  */
 public function getOffsetsBefore($topic, $partition, $time, $maxNumOffsets)
 {
     $req = new Kafka_OffsetRequest($topic, $partition, $time, $maxNumOffsets);
     try {
         $this->connect();
         // send request
         $req->writeTo($this->socket);
         //echo "\nRequest sent: ".(string)$req."\n";
     } catch (Kafka_Socket_Exception_EOF $e) {
         //echo "\nReconnect in get offetset request due to socket error: " . $e->getMessage();
         // retry once
         $this->connect();
         $req->writeTo($this->socket);
     }
     $size = $this->getResponseSize();
     $errorCode = $this->getResponseCode();
     Kafka_Response::validateErrorCode($errorCode);
     return Kafka_OffsetRequest::deserializeOffsetArray($this->socket);
 }
Example #2
0
 /**
  * @expectedException Kafka_Exception
  */
 public function testErrorCodeValidationUnknown()
 {
     Kafka_Response::validateErrorCode(20);
     $this->fail('the line above should throw an exception');
 }