Пример #1
0
 public function testEncodedMessages()
 {
     $topic = 'sample topic';
     $partition = 1;
     $messages = array('test 1', 'test 2 abcde');
     $encoded = Kafka_Encoder::encode_produce_request($topic, $partition, $messages);
     $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 += 9 + strlen($msg);
     }
     $this->assertEquals($size, strlen($encoded));
 }
Пример #2
0
 /**
  * Get the message payload
  * 
  * @return string|Kafka_MessageSetInternalIterator
  */
 public function payload()
 {
     return Kafka_Encoder::decompress($this->payload, $this->compression);
 }
Пример #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 = 4294967295.0)
 {
     if ($this->connect()) {
         return fwrite($this->conn, Kafka_Encoder::encode_produce_request($topic, $partition, $messages, $this->compression));
     }
 }
Пример #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 = 0)
 {
     $this->connect();
     return fwrite($this->conn, Kafka_Encoder::encode_produce_request($topic, $partition, $messages));
 }
Пример #5
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));
 }
Пример #6
0
 private function writeDummyCompressedMessageSet($stream, array $messages, $compression)
 {
     $encoded = Kafka_Encoder::encode_message($this->getMessageSetBuffer($messages), $compression);
     return fwrite($stream, pack('N', strlen($encoded)) . $encoded);
 }
Пример #7
0
 public function setUp()
 {
     $this->test = 'a sample string';
     $this->encoded = Kafka_Encoder::encode_message($this->test);
     $this->msg = new Kafka_Message($this->encoded);
 }
Пример #8
0
 /**
  * @expectedException Kafka_Exception_NotSupported
  */
 public function testDecompressUnknown()
 {
     $msg = 'test message';
     Kafka_Encoder::decompress($msg, 15);
     $this->fail('The above call should fail');
 }
Пример #9
0
 /**
  * Encode a message
  * 
  * @return string
  */
 public function encode()
 {
     return Kafka_Encoder::encode_message($this->payload);
 }