Esempio n. 1
0
 /**
  * Create
  *
  * @param String $connectionString
  * @param Float  $apiVersion
  */
 public static function Create($connectionString, $groupId, $apiVersion = 0.7)
 {
     $apiImplementation = Kafka::getApiImplementation($apiVersion);
     include_once "{$apiImplementation}/Metadata.php";
     $metadataClass = "\\Kafka\\{$apiImplementation}\\Metadata";
     $connector = new ConsumerConnector(new $metadataClass($connectionString), $groupId);
     return $connector;
 }
Esempio n. 2
0
<?php

$kafka = new Kafka("localhost:9092");
$kafka->produce("test", "message yangwm");
$msg = $kafka->consume("test", Kafka::OFFSET_BEGIN, 20);
var_dump($msg);
//dumps array of messages
Esempio n. 3
0
 /**
  * Get producer by broker id
  *
  * Method that given a broker id, it will create the producer and
  * will return it.
  *
  * @return IProducer
  */
 protected function getProducerByBrokerId($brokerId)
 {
     if (!isset($this->producerList[$brokerId])) {
         if (!isset($this->brokerMetadata[$brokerId])) {
             throw new \Kafka\Exception("Broker connection paramters not initialized for broker {$brokerId}");
         }
         $broker = $this->brokerMetadata[$brokerId];
         $kafka = new Kafka($broker['host'], $broker['port']);
         $this->producerList[$brokerId] = $kafka->createProducer();
     }
     return $this->producerList[$brokerId];
 }
Esempio n. 4
0
<?php

for ($i = 0; $i < 2; $i++) {
    $kafka = new \Kafka("localhost:9092");
    $kafka->produce("test123", $i);
}