Exemple #1
0
 /**
  * Get the currently active brokers participating in a particular topic.
  *
  * @param string $topic the topic to get the brokers for
  *
  * @return array an array of brokers (int) that are participating in the topic
  */
 public function brokers($topic)
 {
     $topicPath = sprintf(self::TOPIC_PATH, $topic);
     if (!@$this->zookeeper->exists($topicPath)) {
         if ($this->zookeeper->getState() != Zookeeper::CONNECTED_STATE) {
             $msg = 'Cannot connect to Zookeeper to fetch brokers for topic ' . $topic;
             throw new Kafka_Exception_ZookeeperConnection($msg);
         }
         return array();
     }
     $children = $this->zookeeper->getChildren($topicPath);
     if (empty($children)) {
         return array();
     }
     $results = array();
     foreach ($children as $child) {
         $results[] = intval(str_replace($topicPath, '', $child));
     }
     return $results;
 }