getError() public static method

get error
public static getError ( integer $errCode ) : string
$errCode integer
return string
Example #1
0
 /**
  * get produce server offset
  *
  * @param string $topicName
  * @param integer $partitionId
  * @access public
  * @return int
  */
 public function getProduceOffset($timeLine = self::LAST_OFFSET)
 {
     $topicName = $this->topicName;
     $partitionId = $this->partitionId;
     $requestData = array('data' => array(array('topic_name' => $this->topicName, 'partitions' => array(array('partition_id' => $this->partitionId, 'time' => $timeLine, 'max_offset' => 1)))));
     $this->encoder->offsetRequest($requestData);
     $result = $this->decoder->offsetResponse();
     $this->client->freeStream($this->streamKey);
     if (!isset($result[$topicName][$partitionId]['offset'])) {
         if (isset($result[$topicName][$partitionId]['errCode'])) {
             throw new \Kafka\Exception(\Kafka\Protocol\Decoder::getError($result[$topicName][$partitionId]['errCode']));
         } else {
             throw new \Kafka\Exception('get offset failed. topic name:' . $this->topicName . ' partitionId: ' . $this->partitionId);
         }
     }
     return array_shift($result[$topicName][$partitionId]['offset']);
 }
Example #2
0
 /**
  * Send any records in the kafka client internal queue.
  */
 protected function send()
 {
     try {
         $response = $this->produce->send();
     } catch (\Kafka\Exception $e) {
         $ignore = $this->warning('Error sending records to kafka: {exception}', ['exception' => $e]);
         if (!$ignore) {
             throw $e;
         } else {
             return;
         }
     }
     if (is_bool($response)) {
         return;
     }
     $errors = [];
     foreach ($response as $topicName => $partitionResponse) {
         foreach ($partitionResponse as $partition => $info) {
             if ($info['errCode'] === 0) {
                 // no error
                 continue;
             }
             $errors[] = sprintf('Error producing to %s (errno %d): %s', $topicName, $info['errCode'], Decoder::getError($info['errCode']));
         }
     }
     if ($errors) {
         $error = implode("\n", $errors);
         if (!$this->warning($error)) {
             throw new \RuntimeException($error);
         }
     }
 }
Example #3
0
 /**
  * testGetError
  *
  * @access public
  * @return void
  */
 public function testGetError()
 {
     $this->assertEquals('Unknown error', Decoder::getError(19));
 }
Example #4
0
 /**
  * load next partition
  *
  * @access public
  * @return bool
  */
 public function loadNextPartition()
 {
     if ($this->validCount >= $this->partitionCount) {
         return false;
     }
     try {
         $partitionId = $this->stream->read(4, true);
         $partitionId = Decoder::unpack(Decoder::BIT_B32, $partitionId);
         $partitionId = array_shift($partitionId);
         \Kafka\Log::log("kafka client:fetch partition:" . $partitionId, LOG_INFO);
         $errCode = $this->stream->read(2, true);
         $errCode = Decoder::unpack(Decoder::BIT_B16, $errCode);
         $this->errCode = array_shift($errCode);
         if ($this->errCode != 0) {
             throw new \Kafka\Exception(\Kafka\Protocol\Decoder::getError($this->errCode));
         }
         $offset = $this->stream->read(8, true);
         $this->offset = \Kafka\Protocol\Decoder::unpack(Decoder::BIT_B64, $offset);
         $this->key = $partitionId;
         $this->current = new MessageSet($this, $this->context);
     } catch (\Kafka\Exception $e) {
         \Kafka\Log::log($e->getMessage(), LOG_ERR);
         return false;
     }
     $this->validCount++;
     return true;
 }