Example #1
0
 private function loadTopicDetail(array $topics)
 {
     if ($this->client === null) {
         throw new Exception('client was not provided');
     }
     $response = null;
     foreach ($this->hostList as $host) {
         try {
             $response = null;
             $stream = $this->client->getStream($host);
             $conn = $stream['stream'];
             $encoder = new Protocol\Encoder($conn);
             $encoder->metadataRequest($topics);
             $decoder = new Protocol\Decoder($conn);
             $response = $decoder->metadataResponse();
             $this->client->freeStream($stream['key']);
             break;
         } catch (Exception $e) {
             // keep trying
         }
     }
     if ($response) {
         // Merge arrays using "+" operator to preserve key (which are broker IDs)
         // instead of array_merge (which reindex numeric keys)
         $this->brokers = $response['brokers'] + $this->brokers;
         $this->topics = array_merge($response['topics'], $this->topics);
     } else {
         throw new Exception('Could not connect to any kafka brokers');
     }
 }