refreshMetadata() public method

public refreshMetadata ( ) : null
return null
Beispiel #1
0
 /**
  * get broker host by topic partition
  *
  * @param string $topicName
  * @param int $partitionId
  * @access public
  * @return string
  */
 public function getHostByPartition($topicName, $partitionId = 0)
 {
     $retryAttempts = 0;
     do {
         $partitionInfo = $this->metadata->getPartitionState($topicName, $partitionId);
         if (!$partitionInfo) {
             throw new \Kafka\Exception('topic:' . $topicName . ', partition id: ' . $partitionId . ' is not exists.');
         }
         $hostList = $this->getBrokers();
         if (isset($partitionInfo['leader']) && isset($hostList[$partitionInfo['leader']])) {
             return $hostList[$partitionInfo['leader']];
         } elseif ($retryAttempts == 0) {
             // Its possible a broker dropped out of the cluster during the lifetime of our process
             // We should refresh our cached metadata and retry once.
             $this->metadata->refreshMetadata();
             $retryAttempts++;
         } else {
             throw new \Kafka\Exception('can\'t find broker host for topic ' . $topicName . ' partitionId ' . $partitionId);
         }
     } while ($retryAttempts <= 1);
 }