Exemplo n.º 1
0
 public function testEncodedMessages()
 {
     $topic = 'sample topic';
     $partition = 1;
     $messages = array('test 1', 'test 2 abcde', 'test 3');
     $encoded = Kafka_Encoder::encode_produce_request($topic, $partition, $messages, Kafka_Encoder::COMPRESSION_NONE);
     $this->assertContains($topic, $encoded);
     $this->assertContains($partition, $encoded);
     foreach ($messages as $msg) {
         $this->assertContains($msg, $encoded);
     }
     $size = 4 + 2 + 2 + strlen($topic) + 4 + 4;
     foreach ($messages as $msg) {
         $size += 10 + strlen($msg);
     }
     $this->assertEquals($size, strlen($encoded));
 }
Exemplo n.º 2
0
 /**
  * Send messages to Kafka
  * 
  * @param array   $messages  Messages to send
  * @param string  $topic     Topic
  * @param integer $partition Partition
  *
  * @return boolean
  */
 public function send(array $messages, $topic, $partition = 4294967295.0)
 {
     if ($this->connect()) {
         return fwrite($this->conn, Kafka_Encoder::encode_produce_request($topic, $partition, $messages, $this->compression));
     }
 }
Exemplo n.º 3
0
 /**
  * Send messages to Kafka
  * 
  * @param array   $messages  Messages to send
  * @param string  $topic     Topic
  * @param integer $partition Partition
  *
  * @return boolean
  */
 public function send(array $messages, $topic, $partition = 0)
 {
     $this->connect();
     return fwrite($this->conn, Kafka_Encoder::encode_produce_request($topic, $partition, $messages));
 }
Exemplo n.º 4
0
 /**
  * Send messages to Kafka
  * 
  * @param array   $messages  Messages to send
  * @param string  $topic     Topic
  * @param integer $partition Partition
  *
  * @return boolean
  */
 public function send(array $messages, $topic, $partition = 0xffffffff)
 {
     $this->connect();
     return $this->socket->write(Kafka_Encoder::encode_produce_request($topic, $partition, $messages, $this->compression));
 }